Patterns in Programming: Part I
Just so I don't mislead you, this is not about Adapter, Bridge, Abstract factory, and other dry (yet important) software design ideas.
Instead we will discuss patterns of the programming process and their relationships to musical expressions. This is, more or less, a personal exposé into one of my approaches to writing software.
Like many people engaged in a solitary activity, it often helps to incorporate music as part of the sonic landscape. It is typical to place my multi-GB collection into shuffle-by-track mode; this keeps me just enough on edge so I don't fall into a whispy, dreamy state of mind... I wouldn't want to end up in some error-prone alpha state while typing out, for example, a business-critical algorithm!
Exposition Comes Before Development
if __name__ == '__main__': main() sys.exit(0) Sister Rosetta Goes Before Us, Alison Kraus
Ok, I'm writing a python script, just getting started, and this wonderful tune appears inside my head. The beautiful melody is far more interesting than our mundane
def get_options(): version_info = 'checkipa: version %s' % (VERSION_NUMBER) p = optparse.OptionParser(version=version_info) Fuge Nr. 20 in A minor - WTC Book II, Bach (Glenn Gould)
Yikes! At breakneck speed the script's form emerges as Bach's contrapuntal explorations threaten to overwhelm my concentration. (Did I just hear an implied Neapolitan Sixth?) Anyway, Gould's performance of this mini masterpiece is astounding. Nonetheless, you need to keep your options open, right?
self.plist_file_RX = re.compile(r'bInfo.plist$') Robot Poetry, Penta - Give Me Five!
What's going on here? Well, we're setting up a regex in the constructor to scan the IPA package's file list. Then if we find it, we'll extract this important file for parsing. Oh yeah, I almost forgot: the frenetic pace doesn't let up one bit as Penta's Nikita Tselovalnikov rocks the psy trance party.
def checkBundleID(self): if 'CFBundleIdentifier' in self.data: if self.data['CFBundleIdentifier'].strip() == "": self.errors['bundleid'] = True else: # key missing self.errors['bundleid'] = True Oleo, Pat Martino - Live at Yoshi's
The CFBundleIdentifier, as any iOS developer will tell you, is fundamental — and critical. Thus the script makes sure that the key exists and its value is a non blank string. If the CFBundleIdentifier doesn't meet this basic criteria, then we mark it as an error. Pat Martino, however, couldn't care less about iOS development details; but he obviously cares about creating an exciting guitar solo over Oleo's rhythm changes. And I am grateful for that.
Our python script is not yet done, insofar as this post is concerned. So please come back next week to join the continuation of our musical journey in Part II.