02 May 2008

The Joys of Reading Other People's Code

I thought that it would make sense to read the code for NEAT and for Aria, but it turned out that it was probably not a good idea. The aim was that I would get a feel for what the code does and then I would have a change to write what I need. I didn't get that feel!

What I found was code where there is not enough comments to understand what is going on. Perhaps for the author there may have been enough, and he certainly would understand his own abbreviations (I assume) but there certainly was not enough for me.

OK, I think I probably put more comments than nearly all programmers, so probably I am biased any way. I think both internal and external documentation is very important, I try to use explicit names, although it is extremely unlikely that I will spell them correctly (most APIs don't include a spell checker!), which I am sure annoys lots of people!

Another problem was the indenting. To start with indentation was 2 spaces, which I find doesn't have the visual effect that I need. Secondly half of the indentation was all over the place, now I am assuming that this was the effect of importing the code into Visual Studio.

The next problem was the use of whitespace. In some places such as between identifiers and operators there was no whitespace, making whole lines of code one visually into word, not easily broken up by the eye. In other places there were loads of blank lines between every line of code. Sometimes there were even multiple blank lines between say a brace and the things outside the brace, so that it was not easy to see the connection that the braces made. As I write this I wonder if there were two coders with opposite styles involved, but that wouldn't really make sense. Perhaps importing affected whitespace as well as indenting.

I ended up spending days trying to sort out indenting, whitespace and matching braces, and didn't get much of a feel for the content at all. In frustration I changed indenting to a more Java style that a C++ style, which was probably, but now all the blank lines that are left are essential for comprehension, and probably some of those have gone too.

Finally the other thing that added to the obscurity of the code is the fact that functions, even after removal of blank lines, are often more that 200 lines long. My brain is simply not big enough to follow 200 lines of code in one lump. Clearly I am not a hacker! If a function goes much over one screen full its too much for me.

The length of the methods means that I am not at all sure that my attempt to find matching braces was correct. Does this close the if statement that started 20 lines ago, the switch statement that started 50 lines ago, the else that started 80 lines ago, the for loop that started 100 lines ago, or was it something before that???? Frankly all too often I gave up.

I don't have time to understand what this code does. I hope that I manage to find what I need to use, and don't miss anything too useful. If I use this code in the future I will definitely need to rewrite it.

Now when it comes to the ARIA code, well actually it wasn't much better. So at this stage, I don't know much, and I haven't achieved much!

I think I'll go and eat worms.

(Sorry that is a joke from the old country, I'm Australian now, but it just fits!)