Skip to main content

Development fun

Yeah, you read right, developing software can be fun :) Especially if you stop walking the old roads and try new stuff.

Template metaprogramming

This can be real fun, seriously, as long as your compiler keeps up with you. I can recommend the MSVC++ 8.0 compiler (although, it generates sometimes very weird code) and an EDG based one, preferably the Intel C++ 9.1 compiler. It really kicks ass, provides meaningful messages in most cases and does proper template checking (not that lazy check when you instantiate which MSVC++ does). I've been playing around with those two compilers and some template metaprogramms lately, and I have to admit once you find a good problem domain then it can really suck you in. Finally, you can generate huge amounts of boilerplate code in basically no time. Even if you wind up writing 100 lines of templates, it is still better than 50 lines of boilerplate - if you ever need to change the boilerplate, you will have to rewrite it from scratch, while you should be able to avoid it with the template route. Moreover, the tougher the problem, the merrier :) As an entry, try to write the "dot" product function for a 16 element vector (and using a for does not count, we want HPC style "all-inline" code), and then tell me which way was more fun :). I've rewritten most of niven's math library using some rather heavy template code, and so far I'm very pleased with the results.


In each book about software development, you get told that tests are the most important thing in a good software. If you don't believe the books (or you don't read any ;) ), then believe me: Tests are the most important thing in software development. The immediate pay-off is usually close to null, you spend some time writing them, in exchange you catch more bugs earlier. But the real killer argument is that if you ever come to the point where you are about to change some larger piece, the tests become an invaluable source of information. First of all, they catch bugs, but second, you have to think twice about the interface of your new stuff, and this is more important than I thought. Point in case: In niven, matrices used to provide no special means to access their data (and exposed a pointer to it directly), whereas vectors encapsulated them (yeah, I know, bad design, that's why I've rewritten it). The first rewrite though used vector [1] and matrix (row, column) for accessing. After taking a look at the unit tests, I also added support for vector (1) just to be consistent with the matrices. Without having quite a lot of test code in place I'd probably never spotted this.