SimpleShelf - now with objects!
I worked most of the weekend on converting SimpleShelf (note to self: make project page!) from accessing the XML datastore six different ways to Sunday, to using objects (part of the reason behind this post.)
Instead of a UI module, a "worker" module, and a storage module (just to get data to the main UI and do some basic filtering and manipulation), I rejiggered the UI to use the Books object (subclassed list), containing Book objects, which contains a MARCRecords reference (subclassed list), containing MARCRecord objects (subclassed dictionaries).
The Books object, given a path & told to Load(), loads the data. Save() saves it. At no point does any other module touch the raw data. Filtering gets done by sending in a dictionary - previously, I built XPath statements in the UI module and sent them through Worker to Storage.
The benefits, you ask? Oh, let me count them!
- Less code (for the same functionality)
- More encapsulated code
- Much easier to follow the
bouncing ballprogram flow
- SimpleShelf runs faster in the IDE now than it ran compiled the previous way
- Far easier to troubleshoot (only one place to save, so only one method to debug missing data)
I learned so much writing SimpleShelf - including Python itself. This was my "exploratory" project, the program I created to learn the language. And less than a year later, I'm rewriting it in a much more Pythonic fashion, which is giving me all the benefits of Python- faster, cheaper (lines-of-code-wise), more easily understood.
When I start from scratch again, I shall remember:
Objects. Don't leave the keyboard without them.