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-07-28

catch( Exception e ) { throw new Exception( e ); }

Some Java book I read long ago, I think it was Thinking in Java, explains that one of the benefits of Java exceptions is that you can shift error handling away from the normal path, leaving the implementation of the common case clearer and better.

Fine. There's just one catch: You have to catch the exceptions and handle the error somewhere. (more…)

2011-01-19

Making Maven compile faster

jam -g is the best make system I've ever used. Best for the simple reason that when the build fails, it usually fails quickly. I start the build, and a second later I'm already looking at my mistake. That feature outweighs any and all drawbacks.

Sadly, I don't use jam very often at the moment. I mostly use maven 2, which starts the build by determining from first principles which source files to use and which libraries to download. In practice the set needed hasn't changed in the past minutes, (more…)

2010-01-29

Javadoc

Javadoc is built in to Java, but I think they botched it. It's clear that they didn't care deeply: JLS3 grammar doesn't mention javadoc at all, and the JLS doesn't specify it, hardly even mentions it… the word stepchild sounds more appropriate than does builtin, in my oh-so-humble opinion.

There are many things I don't like about the result, and few things I do like.

There's too much typing for not enough benefit. (more…)

2009-11-12

Exceptions, and exceptions, and exceptions

Exceptions are such a pain. They look as if someone thought they could solve many disparate problems with one tool, and in the end, the tool doesn't look terribly elegant, and people don't use it terribly well. (more…)