uwMike.com

I'm in Waterloo at the moment, and next available to work in September 2008.

Programmer’s Euphoria

April 8th, 2005

There’s a unique sort of delight to be felt when you know you’ve created something marvelous. It’s likely that artists of all stripes feel similar joy about their best works, but I experience it where I’m most at home: programming.

Programming Problems

I’ve been recently faced with a fiendishly difficult programming problem which shouldn’t even exist but for a bizarre set of circumstances at the client. It’s the sort of problem where there’s no such thing as a clean solution.

No matter what it was, it would be ugly.

Like painting a picture, there’s no perfect way. But the limitations of paint are in their ability to capture the entirety of a scene, whereas there are some behaviours of a program that simply cannot be simulated without an extraordinary amount of non-reusable code.

Inside The Box

Thinking ‘inside the box’ can be one of the biggest enemies in these situations. The ideals of abstraction and data-hiding lead to much more maintainable, bottom-up code. But there are those places where a tool has many purposes. A screwdriver is a screwdriver, but it’s also half a crowbar.

I found it helpful to think in terms of extremeties. Lay out the worst possible approach that would still work, even if it’s too ugly to be feasible. Then lay out the absolute best approach in broad strokes, even if it’s unfathomable how a particular piece of the functionality will be implemented.

Look at the worst-approach picture. Try to grab at anything that can be abstracted, any kind of general case that can be drawn between the different cases.

Impasse

The most successful false start lasted for several days, until I suddenly realised with a sinking heart that would not work. The design was impossible.

What to do then? Go to the water-cooler. Play darts. Cycle home and think about it. Have a shower. Percolate.

In the morning, I’ve got a solution. It’s not perfect, but it will work. And it’s significantly better than the worst-case-scenario. By lunchtime, it’s working, using large pieces of code that was written for the prior attempt.

Teamwork

It’s so important for programmers to work in small teams, and idea-bouncing is one of the many reasons. New eyes can so easily see value in something you’re ambivalent about, or better yet, see the problems with your idea.

Programmer Pride is another reason. When a piece of code just works, it’s so great to be able to show it to others who understand the significance. Like design, the best programming looks easy. The best programs do work for you without even letting you know. Sharing source with others is a way of demonstrating how cool something is under the hood, and sharing a little of the excitement.

Solution

The problem is solved, and development will move forward, spurred on by the knowledge that there’s something nifty in there.

Mike

Discussion

  1. I always have an urge to program like a horse with blinders on…. It usually backfires on me though.

    You’ll have fun in Gene240, lemme tell ya…. travelling salesman problem… ugh.

    Posted at 11:44 pm on April 13th by Kenshi.

  2. Mike, I’m sitting beside you in the GenE labs…just so you know

    Posted at 6:26 pm on April 14th by Ryan.

  3. Ryan: ah haha.

    If last term is any indication, one has to be careful thinking up really good solutions… Remember my pythagorean triplet program that pre-cached the squares to avoid hundreds of calls to sqrt()? The one that lost points for “running three loops instead of two, making it slower”? Yeah…

    Posted at 9:33 pm on April 14th by Mike Purvis.

  4. got torn apart in gene121….torn f***ing apart….no programmin experience really helped me out too…..gonna have to end up learnin how to (as in completeing assignments in less than 6 hours) eventually. im sure you werent amazin at programmin before….so im REALLY interested in gettin some useful advice on how to learn to program effectively and efficiently…thanx

    Posted at 10:18 am on April 15th by programming hates me.

  5. Well, I can say from first-hand experience that teaching programming is both extremely rewarding and tremendously difficult. There are so many marvelously clever tidbits of knowledge to be imparted to the students that it’s a huge temptation to get ahead of oneself. I think that happened a few times in GenE121: Bedi rushed through the boring bits to get to the fun bits, alienating those who had never before seen the important boring bits.

    See, hacking is the most fun when you’re solving a new problem. Or you’re creating a drastically superior solution to an old problem.

    At work, we’ve solved a ‘new’ problem that few will ever face, since it’s borne out of contracting mistakes that hopefully not many make.

    On my own time, I’m experimenting with a webapp that makes extensive use of flat files and symlinks as its data structure. I believe it’s a new approach, but even if it isn’t, it’s new for me, and that makes it exciting. Perhaps it will be terrible and I’ll give up on it, but at least I’ll have tried it and be the wiser for having done so.

    Posted at 5:11 pm on April 15th by Mike Purvis.

Leave a Reply

You can use Markdown for style. I love hearing from readers, but please don’t hijack the discussion, use offensive language, or try to sell anything.

© 2004-2008, Mike Purvis, some rights reserved. I'm running Wordpress, and I have an RSS feed.