Tuesday, January 18, 2011

More Bullshit Code!

In the last installment we looked at some code that implements the "added view column" (ac) feature of my column search program. I demoed it in the comment threads here.

The column search (hacols) is the program whose output I often post in the comment threads. One day I needed a convenient way to assemble a url to a specific comment from parts I had already been collecting and thus the "added view column" feature to hacols was born. The feature allows me to develop a short one-liner program on the command line and then once it's working, store it to be recalled for later use. It becomes just another column (albeit unsearchable) for views of the database. So far I've used added view columns to generate comment urls and to downcase and strip out html from comment bodies. Check it out:

Click on the graphic above to see it better.

Blogging this code led me to thinking. Counting the results of a search and executing view code on those results is at present an either/or. One bit of code that executes later is the "uniq" feature which filters out redundant results. What if I wanted to count the unique results of a search like all the variations on Puddybud's handle in the comments file? Uh.. I can't do that with this code. And yikes! What's with copying tr to a results array? Why not update tr in place? What a waste! And sigh, it makes sense to do that inject only when adding columns at the command line not every time we convert the vetted code strings to procs for view execution. Ditto for storing. How humbling...

So the big if statement drops to the cutting room floor and the following refactor is born. Here:

 and here:

What a difference a little time and blogging makes. Brand new code next time.

Update: Found yet more optimizations for larger result sets. I won't discuss them. I promise.

No comments: