Problem Solving Flowchart

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

Tech Support Cheat Sheet

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

Twitter Down due to DDOS Attack

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.

Using BOOST_FOREACH for Simpler Iteration

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.

Image | WordPress Themes