Showing posts with label Code. Show all posts
Showing posts with label Code. Show all posts

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!)

17 April 2008

Visual Studio Gymnastics

Well it turns out that visual studio 2003 doesn't work on Vista, and is not going to be supported. It just wouldn't work and in the end I had to uninstall it, you forget how many hours it took to install.

Obviously I scanned have used a 2008 after all, is searching on the Web founder couple ways that might get it to work. Next stage was that she trying to use visual studio which is slightly less than intuitive. OK I could write a "Hello World" program, though in the existing projects turned out to be problematic. But after few days everything was hunky-dory.

For one thing when opening the project from an earlier version, don't try opening visual studio first, and then browsing to the project files from within the program it won't open them. On the other hand, opening of projects files from the Windows directory causes visual studio to convert it to the current version.

Another problem I had was something that was a registered bug in visual studio 2008, after spending the day trying to find a solution to that,, I went looking for another solution. I eventually found the Visual Studio 2005 Express Version download page hidden away on Microsoft's Web site.

Using 2005 learned more lot more about conversion programmes from other versions of Visual Studio, and about the aria operating system in particular. It looked like I'd found the solution.

The next step was to convert the neat program to visual studio 2005. Once again ran into problems, NEAT had numerous compilation errors in 2005, and not just undeclared variables. I converted the NEAT code to Visual Studio 2008, and I was able to compile at once I'd fixed at the undeclared variables. I returned to trying to convert the Aria code to 2008 and eventually had success.

Having eventually compile the code the next step was to get it to run on robots. After a number of attempts, we found a utility that allows 2008 code to run on the robots. In fact we were able to run both the 2005 and the 2008 code.

Success at last!

Next, actually writing my own code, the body of my project.