Wednesday, June 6, 2012

The Art & Craft of Computer Programming

The best cooks talked about the very basic elements of cooking.
- Michael Ruhlman, The Soul of a Chef

I talk quite often about my adoration of Chef Gordon Ramsay, because of his relentless drive for excellence. His Kitchen Nightmares show, while following a cookie-cutter approach of fixing the dynamics between the owners, cleaning the filthy kitchens, cooking simple, fresh food and having an attractive place in which to dine, re-enforce his belief in quality. It doesn't matter if you're paying $300 for a meal, or $30, you should still have a good, fresh meal, in a nice looking place, with a pleasant atmosphere.

I'm turning my back on words now
no more weighing the worth of observations.
the poet's voice dried with the search for perfection,
and i just wanna sing a simple song.
- Poi dog Pondering, Simple Song

Likewise, I talk a lot about certain bands, most notably Poi dog Pondering. In 25 years, they've put out seven studio CDs and a handful of live ones. Certainly not the most prolific of bands (witness SAGA, with something like 31 CDs since 1987), they continue to stay true to the current vision of the leader, Frank Orrall. Each live show leaves the audience in a state of euphoria - more seasoned "Poi Pounders" collect in certain areas, talking amongst themselves, discussing different versions of songs, comparing setlists and catching up with each other's lives - like junkies unwilling to leave the crackhouse, even though they've just scored, while "Poi virgins" wander around like the newly converted, silly grins like they've just been told the secrets of the universe.

Part of the attraction is the music, strong beats that ebb and flow, pulling you along with them, but a major part is the charisma and force of conviction in both Frank and his bandmates that what they most want to do, what their primal purpose in life is, is to play for their friends, and at that moment, you are among their closest friends.

Cooking and music are, to me, two examples of industries that marry art and craft together. To create the perfect meal, the cook has to pick out sublime ingredients that go well together (artistry), and execute the physical cooking flawlessly (craft). Only the crafting part can be taught - the rest needs to come from within your soul Likewise, anyone can learn to play a guitar (maybe not on par with Eddie van Halen or Eric Clapton), but to be able to have a solo that makes the crowd explode with excitement takes both confidence and that inner spark of talent.

It is with these traits in mind that I want to have a mini-rant against computer programmers.

Recently, one of our software vendors and I had a discussion about an issue we had where the software worked one way, and we needed it to do something different [yes, I'm being intentionally vague]. He had me explain the problem in detail, then we looked at how the program worked, and then he asked for some time to come up with "an elegant solution."

Originally, I balked, thinking that we don't have time to waste when a fairly obvious solution easily presented itself.

But then I took a second to really think about what he said..."an elegant solution." I realize that in three words, he summed up the biggest beef I have with the work of many programmers over the years (and I'm sure I'm including myself in this).

Many times, programmers look at their current assignment and do the literal change only - not taking the time to read surrounding code or to understand the requirements better. This might be OK for junior level programmers (who should not be writing completed logic without supervision), but far too often more experienced coders fall into the same pitfalls.

Additionally, they will just put the patch in place as quickly as possible - instead of re-writing sections of code that can be made more efficient and cleaner - creating the eleqant solution. While this is perceived to be working efficiently (because you can quickly make the fix you need and move onto the next task), it ultimately decreases both the programmer's productivity and increases the likelihood of future bugs because these lazy and sloppy coding techniques lead to logic errors - errors that might not be caught during the QC and testing phase, and may not actually be found ever...until a new business requirement forces a change upstream that causes your poorly written changes to fail.

For example, let's look at a report that would originally print the invoice number and the invoice status (which is a single digit field). Users are requesting that the status be an English word that shows the status (i.e., Open instead of O). Joe Programmer makes a quick change to the program, and adds a simple CASE statement to display the field. [Don't worry, you do not need to be technical or proficient in our programming language to understand.]

          INVOICE.STATUS.DESC = 'Open'
          INVOICE.STATUS.DESC = 'Closed'

What the above code block does is checks the value of INVOICE.STATUS and sets a new variable (INVOICE.STATUS.DESC) into something more user friendly. Then, it prints the invoice number and status description (probably to the printer).

A correct CASE statement should always have a CASE 1 phrase that sets the values to an error condition. However, this is not required, so many programmers leave it out.

Using the above example, let's look at three invoices (0001, 0002 and 0003). The first and third invoices are open, but (using new VOID.INVOICE logic), the second one has a status of "V." Here is what would be printed:

0001        Open
0002        Open
0003        Open

Everything looks good, but it's wrong! Joe should have added the following two lines of code to his change:

     CASE 1
          INVOICE.STATUS.DESC = 'Unknown'

The users would then have seen the lines below and called to have someone fix it.

0001        Open
0002        Unknown
0003        Open

Programmers: Take inspiration from your favorite musician. Eat a good meal and admire the craftsmanship and artistry involved in the whole experience. Spend time looking at other people's code, understanding how and why they wrote something one way (vs the way you would have done it). Go the extra mile and do the work properly.

Remember - cooking, being a musician and programming a computer can all be taught to anyone willing to learn. However, you need that desire for perfection to open up the artistic side needed to become truly excellent at your profession. Like the Gatorade you have it in you?