
Recently I’ve been reading Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin). This is a must read, and I’d recommend it to programmers of all skill levels. It has reminded me of many things that I’ve mistakenly unlearned over the past few years as I’ve struggled to battle against tighter and tighter deadlines and push out as much functionality as possible.
One of the main points that I’ve taken from the book is that comments make programmers lazy. For some reason we seem to think we can name our variables anyway we like as long as we give them a nice descriptive comment. Likewise, instead of refactoring code into nice methods with expressive names that follow the Single Responsibility Principle, we tend to create long functions that do many things and again litter them with comments describing what we are trying to do. This leads to problems, as our comments can be misleading, without actually reading and understanding the code we don’t know what is really going on.
My new years resolution is to comment less. In fact, I plan to write as few comments as I can. Instead I will concentrate on writing expressive code that speaks for itself. This will lead to some quite lengthy function and variable names, but I’m a fast typer. So do you think comments make you lazy? Or are they a necessary evil or the limited expressiveness of our high level languages?
Since I have a bit of spare time on my hands at the moment, I thought I’d get back into playing around with Boost. Since my Simple Guide to Installing Boost on Mac OS X article was published we have had a few new releases of Boost, and more importantly a whole new version of Mac OS X. So does my guide still work?
It does still work as I described in my original article, but I have found one slight problem. When I try to compile a project using one of the dylib libraries I get link errors. It seems XCode projects are now defaulting to 32/64 bit combined binaries. The original build instructions only compile pure 32bit binaries so we can either switch our XCode projects to pure 32 bit or we need to compile Boost with the 64bit architecture.
The fix for this is simple, when you compile your binaries with the bjam command simply use the following command line:-
./bjam architecture=x86 address-model=32_64
This will give you a pure x86 (No PowerPC) set of binaries that are both 32bit and 64bit build compatible. You could use:-
./bjam architecture=combined address-model=32_64
To get both Intel and PowerPC compatible binaries if you need them. Once you’ve done this you can carry on using Boost as usual.
If you got a kick out of yesterday's flowchart, I know
Keiron did, here's another one. This one has been kicking around our office for years, there is a crumpled up coffee stained copy sat on the desk behind me. It always gets whipped out whenever we find one of those killer bugs on the day of a big software release, or when somebody decides to flip a power supply to the wrong voltage when it's plugged in. You know, all those stupid things you do that you hope won't get noticed.
Anyway, that's probably it from me for a while. I'm off on holiday for a few days, and for the first time in ages, won't have access to a computer. I have some articles in the works for when I get back, so watch this space for something a little more interesting.
Posted via email from krelborn’s posterous

Ah this comic is so true and should probably be read by all my friends, family and co-workers. Us computer types don’t know how to use every computer program in the world. What we are good at is working out how they are used based on a few simple rules. Most computer software is designed with the same basic principles in mind so it is familiar and easy to work out where things are, think of the items under the standard Edit menu as a perfect example. However, I do remember when the latest version of MS Office came out with the new Ribbon interface, which left me completely confused, it truly was an experience of walking in another man’s shoes, actually, it was a woman’s shoes, my mums.
Posted via email from krelborn’s posterous
The Fail Whale strikes again! According to this Guardian article, Twitter has been down due to a Denial Of Service attack since 3pm. I’d tweet the link, but obviously I can’t. Oh no, I can feel the shakes starting as I haven’t been able to look at my twitter stream for a few hours. Oh well, I’d use Facebook but my fear of flying sheep and superpokes prevents me from logging in
.
Edit: OK, so it’s back up now. Looks like twitter gadget on my iGoogle page hasn’t realised yet. Logging into twitter.com is working. Guess the Twitter guys payed the ransom or relocated their servers to OZ.
I’m working on a little C++ project at the moment. As part of it I’m trying to learn more about the Boost libraries and do clever things with the STL. I have found myself writing a lot of simple loops that iterate over containers of objects and do simple things like call a method on each object. I get tired of writing iterator code like this, it’s something we end up doing a lot as C++ programmers. The syntax for defining and using iterators can be a little long and it can be a right pain to debug if you make a simple typo.
Enter the BOOST_FOREACH macro. I am aware of the STL for_each() function that uses some fancy binding objects to do all sorts of clever stuff. Boost Bindings extend this and create a really powerful set of tools. The problem with this stuff is that it looks a bit weird and isn’t that easy to understand. While I was reading tutorials I came across BOOST_FOREACH. This simple macro gives us something very similar to the foreach keyword in C#.
Imagine you have a container of objects of class Foo, and you want to call the Bar method on each instance of Foo. Usually I’d write something like this:-
for( vector<Foo>::iterator f = container.begin();
f != container.end(); f++ )
{
f->Bar();
}
The BOOST_FOREACH macro can cut out some of the donkey work by doing all the iterator stuff for us. So here’s the above example using BOOST_FOREACH.
BOOST_FOREACH( Foo &f, container )
{
f.Bar();
}
I like this alternative because it’s a lot cleaner than the classic version and it will work the same with both STL containers and standard C arrays. You also end up typing less and so inevitably will make less mistakes. It’s not going to work in all circumstances, any code where you want to manipulate the container itself is probably a bit risky, but it makes doing simple stuff a bit easier and leads to better code without having to get bogged down with templates and std::for_each.
I came across this article titled Maker’s Schedule, Manager’s Schedule. It makes a very interesting point about the effects of meetings on a Software Developer’s productivity. I have to agree with everything in it. My personal experience is that a meeting completely blows at least half a days development. I need long periods of time to focus on a task, find my zen and really get to grips with solving the problems I am working.
Since I became a team leader, I have tried to avoid organising unnecessary meetings, especially when it is obvious that the team have their minds on what is important to us all, their code.
What do you think? Do you find breaking up your day with meetings means you get less real work done?
I’ve always had a desire to make computer games. It obviously stems from my misspent youth playing Nintendo and getting a serious case of SAD. Sadly, I’ve grown up now and spend my days writing code instead of playing games. I’ve not realised my dreams of becoming a professional games designer but it’s something I’d like to do as a hobby.
I’ve been doing a fair bit of hunting round to find a decent set of tools to get me started. Coding everything from scratch doesn’t really appeal to me so I want something that does all the donkey work of setting up windows, graphics devices, sound and controller input, without being a full blown Game Engine. I also don’t fancy learning another programming language, so ideally it will be a C++ library. It must also be cross-platform as I use both Mac and PC. During my search I’ve looked at SDL, Allegro and Gosu and have decided that Gosu is definitely the way to go.
Gosu is pure object-oriented C++ goodness (Ruby bindings are also available), the API is neat as it is made up of only a small collection of classes. It is primarily for 2D games but it has support for mixing in OpenGL if you are brave enough to do some 3D. It is built on top of the Boost libraries (See my previous post on Installing Boost), so if you need advanced stuff like threads you can get those without too much hassle. It’s also cross-platform as there are binaries for Windows, Mac OS X and Linux. One of the real bonuses is that it is actively being developed and has some fairly comprehensive online documentation.
The getting started guides on the Wiki are great, and walk you through all the basics from installing and setting up a project, to writing a simple game. After I’d got everything installed properly it took me about an hour to code up a really simple Snake game clone from scratch. I’m going to play with it some more and see if I can knock up something a bit more advanced. Next stop Space Invaders!

Two weeks ago I was complaining about the default Akismet Spam Protection that comes installed with Wordpress. It has always been a bit of a pain having to trawl through the spam trap once a week to pick out the odd legitimate comment, so I stopped doing it. After a brief blogging holiday I came back and found a few nice comments rotting away under Spam. I posted a bit of an apology and a complaint and then Keiron suggested I try WP-SpamFree, a Wordpress plugin that he was testing.
It takes a more pro-active approach to spam protection. Rather than act as a simple filter that places spam in the Spam Trap. It completely blocks spam posters and particularly bots from leaving posts. It is really effective at this and means there is no spam to search through at all. Great if you get lots of incoming spam or are just a bit lazy like I am
.
Well I’ve tried it out for two weeks, and I can now give it a hearty recommendation. It has managed to block those dodgy russian comments (Anyone else get these?), spam links, and all the other nasty stuff I was getting, and as far as I can tell there are no false positives. My traffic has increased a bit over the last couple of weeks and this plugin has saved me a bit of work, and a lot of headaches, as spam attempts have gone through the roof. So if you hate having to manage spam comments as much as I do, give it a go.
photo credit: vic15
URL shortening has been around a long time. I’ve been using tinyURL for ages. Recently Twitter switched to using bit.ly as its URL shortening service. I signed up for a bit.ly account the other day and have discovered fun in its statistic tracking. For each short URL it generates, bit.ly provides a page that gives information about the number of clicks, location of the clicker as well as a list of tweets, friendfeed comments and comments from BackType that refer to it.
I am now obsessed with tracking my links and looking at the statistics for other pages. It’s really interesting to see the buzz a page can generate as well as how quickly the clicks are generated. It’s worth signing up and using the sidebar bookmarklet for a bit of real geeky fun.