Skip to content

Haskell modulo excess theory

My journey through Haskell is on something of a lull, but John Wiegley’s got you covered. He’s documented his own journey learning Haskell, and it’s very accessible.

John starts with simple stuff like Fibonacci sequences and splitting strings, then jumps straight into modeling Schroedinger’s cat using a monad. Next he gets pretty practical, for Haskell at least: doing text manipulation ala scripting languages to drop command-line arguments and then to MacPorts packages. Finally, he reflects on thinking lazily and using infinite streams.

If you’ve been wondering what this lazy, pure, strongly typed functional thing is all about but keep falling asleep through the intense theoretical bits (there’s a lot of it!), these are a great starting point.

When to do test-driven development

I believe that writing code using testing1 as a design activity yields long-term benefits that make my life easier.

Though I’m a strong believer, I’ve struggled with TDD in the past. I’ve found I get bogged down in keeping the red-green-refactor cycle going. Sometimes I have to work with code that is lacking sufficient tests, but I know I can’t boil the ocean before I proceed to whatever I’m really trying to do with the code. Other times, I’m not sure if I’m testing the right things; I could be missing tests in one place and writing too many tests in another.

Three easy pieces

Last week, I read three insightful pieces and made one discovery of my own that deepened my understanding of the practice of TDD. Allow me to share.

First off, Kent Beck has been exploring the phases in the life of a startup. The earliest stage is proving the idea. He later asserted that when you’re doing stuff like this, you can drop TDD, temporarily. I thought about this and it clicked. If you’re working on a prototype, where you’re trying to explore an idea and see if it works, you don’t want to iterate on the code, as TDD would have you do. You want to iterate on the idea. TDD will just slow you down.

Kirby building

On the other end of the spectrum, you’ve got maintenance programming. Once a startup, company or project has proven their idea and shipped a system, you are maintaining software. Keeping it working, living, breathing. For this sort of development, where you’re making small, focused changes without adding significant functionality, Tim Bray pointed out that TDD is critical. Using it to drive the process of fixing bugs, cleaning up the system and adding minor functionality is really handy for figuring out if you’ve broken something in some dark corner. It also helps the next guy to do the same. It’s a win, and I suspect it’s the sweet-spot of TDD.

If you imagine prototyping and maintenance as opposite ends of the software life-cycle spectrum, adding significant new features to existing software probably lies somewhere in the middle. You may need to “poke around” to decide if what you’re doing is right, like when you’re prototyping. But once you’re done, you want some way for others who have to maintain the software (such as yourself) to figure out what it’s supposed to do and whether assumptions have been broken.

Then I read an anecdote by Uncle Bob about how he worked out an ambitious new feature in Fitnesse. He and his pair got a new feature working, celebrated, and called it a night. When he woke up, he realized they weren’t actually done; they still had to clean it up, by writing tests.

Oh. Duh.

This was the missing link, for me. Sometimes, you need to iterate on the idea first. If skipping the tests helps you, so it goes. Once you’ve got the idea working (and committed!), then start writing tests2. Once you’re happy with the structure and coverage of your code, you commit again and then push it to your peers3.

The crux of my revelation is this: you get the benefits of TDD-as-a-design-activity by doing it. When you do it is immaterial. You just have to do it.

My own revelation is blindingly obvious in retrospect. If the going gets tough, proceed in this order: get it to work, write some tests for it, then clean up the code. Sometimes you can break this cycle if what you’re working on doesn’t take too much cognitive capacity. But if you overflow your mental buffer, you have to break it down into steps and work through the cycle. Failing to realize this was one of the causes of me bogging down in TDD.

Context is everything. Always.

Adding context to answer the question of when you start writing tests is something I haven’t found much writing on until recently. I’m increasingly finding that considering the situation is a great ninja-move in my quest towards writing beautiful, useful code.

1 Call it a test, example, behavior, or story. Whatever.

2 Jim Weirich did a great presentation on how to backfill tests on existing code.

3 Pardon the Git-centric terminology4.

4 If you are not already, please start using Git immediately.

A slide in the workplace

The Red Bull headquarters in London has a slide going between floors.

Awesome slide

I want to go to there. Photo credit: Alexander K.

Super Mario motors

Too cool - Super Mario stepper motor music:


Of course, an Arduino is involved.

Meaningful work

Going to meaningful work:

Just like being awake is more than just having your eyes open, going to work should be more than just being at a workplace trading time for money. It should be meaningful. But where does meaning come from? Of course, it comes from ourselves. We put meaning into things, and share our meanings with others, and teach each other how to build meaning out of what is in front of us.

Buster’s on to something here. He’s articulating one of the qualities I find in the best developers: what they do has meaning and matters to their personality. They are working to make things that result in greater happiness for themselves and others. Their passion is manifest in the quality of their code.

You should also check out Buster’s personal site. He’s got a neat info-graphics, personal data-mining thing going on there.

Breaking with tradition

For the like-minded aficionados of the non-traditional: A Redis implementation of Twitter, designed for learning about non-relational datastores and Clojure’s creator Rich Hickey on state (bonus track: Jonas Boner on the same). Derek Sivers on the fatal determinism of declaring a goal or as I like to say, “the reason you find so many weblogs with one post promising to post a lot”. Michael Heilemann on the lack of good fiction in contemporary games.

The joy of enigmas

…thinking about an enigma. There it is before you — smiling, frowning, inviting, grand, mean, insipid, or savage, and always mute with an air of whispering, ‘Come and find out.’

 — Joseph Conrad, Heart of Darkness

Poisonous people and genius programmers

Brian Fitzpatrick and Ben Collins-Sussman have done a couple great talks on probing the important social aspects of software development, especially in the open source arena. Open Source Projects and Poisonous People talks about how to survive “that guy” joining the community of your favorite project, be it open source or not. Their most recent jam, The Myth of the “Genius Programmer”, tries to temper the romanticism that developers can magically put forth reams of brilliant code. By proceeding with humility, one can appear as a genius without all the hubris and potential for downfall.

See also: my OSCON 2007 talk on PeopleHacks.

Meditations on golf

We’re just wrapping up that nice time of the year in Texas. Technically, we get two nice parts of the year: the one after "winter" and the one after SUMMER. It’s nice in that you can sit outside with the dogs and just enjoy the air, the sounds and the fact you can sit idly without wishing you were in a climate-controlled environment.

This year I’m actually taking advantage of this part of the year by golfing. All the public courses are blooming: the fairways are green, the bunkers are as sandy as they’ll get and the greens are in peak condition.

My golf game is improving; a novel experience. I’m hitting some fairways, some greens and making the occasional nice putt. It’s like seeing an investment pay out. Hopefully I’ll finish the summer hitting under 100 on a regular basis.

Golf is nice, for me, because it’s as close as I get to meditation. I don’t think about code, politics, or finance. I just think about the previous shot and the next shot. In fact, the less I think, the better I do. Golf is my chance to attempt nihlism.

Golf is relaxing. It’s a little vacation. I sometimes see guys out with their wives. They’re doing it wrong. The point of golf is to spend some time away from everything. By this definition, professionals like Tiger Woods are doing it wrong too. Maybe I’m on to something here.

There’s a moment in my game, somewhere on the last three holes, where I realize I’m going to have to go back to being responsible. This moment is like hitting a bad shot; you think you can do better. On the other hand, it takes a long time to play eighteen holes, so getting back to responsibility is a good thing.

What would I do if I didn’t play golf? I don’t know. Golf, as lame as a lot of people think it is, does good things for my brain. Maybe that explains my obsession/addiction. Luckily, I’ve given up my Call of Duty 4 addition. This Old Republic game could prove troublesome though…

Visualizing language trade-offs

Guillaume Marceau has done some excellent work crafting the data from the venerable Computer Language Benchmark Game into visualizations that quickly show the trade-offs of using each language. The speed, size and dependability of programming languages puts each language in a small graph that simultaneously shows the execution speed and program size of each test for every language. From there, the characteristics of each language is manifest. He then goes on to consider whether functional languages display unique performance/size characteristics.

This is a must-read. It’s also great information design, proving that programming language esoterica needn’t bore the reader.