I spent about four hours this evening building something out of lego, something I'd not done seriously in a good many years.

I was suprised how much it felt like starting writing a program from scratch, and how many parallels I kept finding between snapping the bricks together and writing code. Here are just a few of them.

  • The first decision I made, and certianly the most important one, was how the legos were oriented. Were the pointy bits pointing up? (I chose a non-traditional pointy bits forward layout.) When starting a new program, the first and most important decision is which language to use. Both decisions, though crucial, tend to be made fairly arbitrarily.

  • I started putting blocks together with no clear picture of how everything was going to look in the end, though I knew the rough outlines. And it shows in some uglinesses aspects of the final piece. This happens in programming too. But sometimes, it's not worthwhile to figure everything out before you start.

  • The best building blocks are the simplest and plainest ones.

  • The first blocks I put together, I added more things on top of, and eventually the early first bits were found to be unncessary (everything held together without them) and removed. But if I hadn't put those blocks together to start with, I'd have had nothing to build on. When writing a program, I try not to write throwaway code. Instead, I write documentation first, and build the program from there.

  • There were some random accidents that ending up giving the piece personality and were retained.

  • Once I got in the zone, I wasn't just putting blocks together, I was juggling a lot of plans and desires and info in my head, and arranging for them to happen, while keeping everything solid and fitting together well. That's what coding is all about to me, not writing lines of text.

  • I built in all sorts of little features that you probably wouldn't notice if you looked at the piece, unless you used it in just the right way, or in a particular situation. I also built in one or two little in-jokes. My code is like that, too.

  • Deep inside my lego creation there's one really ugly hack. It wouldn't work without it, but it's something you shouldn't do with lego. Re: my code -- no comment.

discussion