Arnt Gulbrandsen
Send me mailAbout meAbout this blog
2011-08-19

for() is evil

Consider the function Message::acceptableBoundary(). That function's reading order is exactly the same as the its execution order. This is not unusual in C and C++ (and more or less in Java), but there is a significant exception, for(). Here's an example where the execution order is not the same as the reading order:

int i; for( i = 421; i < 692; i++5 ) { foo( i );3 bar( x[i] );4 }

The brain is really good at detecting rules from patterns or almost-patterns, so I think using for() is tempting fate. Much better to rewrite and spend one more line and three more printable characters:

int i = 42;1 while( i < 692 ) { foo( i );3 bar( x[i] );4 i++;5 ) }

The pedantic reader will now mutter about *p++ = *q++; and be right. That saving is also not worth it. Use the three-character workaround. Ditto function arguments with side effects.

2011-05-09

On Jira

Jira is what I'm supposed to look at in the morning. It tells me what's urgent. What I should fix. It's almost never anything I really want to do. I want to write code. Something that's challenging, with a useful result.

Telling me to open a web browser is not a good way to make me perform chores. Sorry.

2011-04-22

A sort of bug tracker

All bug trackers suck. That's why Abhijit and I really don't want to use one for aox.

Here's what we do instead. It's subtle.

There's a notes file in the version-controlled source tree. The only way to add to a note (ie. file a bug) is to make us do it. There are some scripts that look at the file. (more…)

2011-04-06

Into the flow, quickly

One really good thing I learnt from working with Abhijit on Archiveopteryx is how to get quickly into the flow. Click, flow.

The basic pattern involves a good kind of task, and a good way to get to it. Both parts are vital. (more…)

2010-06-18

Building a balanced binary tree from sorted input in O(n)

Writing about Knuth's literate programming book reminded me about when I met him (at a conference) and asked why the following algorithm wasn't in TAOCP. He grasped the algorithm from a ten-second description, and said it wasn't there because he didn't know about it. Good reason.

My TA at university (when I invented it for an exercise) wasn't aware of it either, but unlike Knuth, my TA didn't understand it. And I hadn't commented the code at all. Sigh.

Here are some words in sorted order: (more…)

2010-04-26

Parser generators

I have a feeling that most (all?) parser generators are written with one overwhelming goal: Parse fast/well when the grammar and input are both correct. (more…)