Critiquing the code of an amateur

May 8, 2015 - Visual Basic

One of the things I find myself doing occasionally is looking at my old code. When you have over a decade of source code and projects that you’ve worked on, you can, perhaps ironically, learn a lot by reading your own code. When you read your old work, you really should seldom be impressed- that’s not a good thing, by any means, because it means that you have become a better developer in the meantime. It’s when you find your past self to be incredibly skilled even relative to yourself now that you may need to consider that you’ve stagnated. Following this, I thought I would write about some old code I wrote, provide it, and point out where I went wrong and where I went right.

As an example, pretty much my first program that did anything useful was a small Visual Basic 2.0 program, which allowed the selection of colours for HTM LBody tags (the old BGCOLOR, TEXT, LINK, ALINK, VLINK, etc settings), this, despite working with 16-color graphics. At some point, I became rather- obsessed- with gradients. Styles, colours, easing…. the signs of insanity were all there. Thus was the start of my first “Module” for code-sharing- “GRAPHICS.BAS”.

GRAPHICS.BAS ballooned in size as I basically just slapped all sorts of functions into it. the seed was “paintfrm” which itself became rather ridiculous. The comments make me incredibly glad that I was not regularly posting on the Internet at those times, and interestingly I see the symptoms today, where somebody who is 15,16, etc. seems to think they have it all figured out and their silly little program/routine should be heralded as creating a new era for humankind- but that is another story altogether. Just glad that my early contributions to the world wide web are difficult to associate with me personally, as they are quite embarassing.

Despite them being somewhat cringey, I kept the comments in the function intact. This is a Visual Basic routine, and it is rather long.

Just look at this. The hubris in the comment at the start. It uses a few other functions (regularPolygon, HLS, CMY) but those have the sort of implementation you would expect (dare I say, reasonable). What can we say about this function? Some obvious considerations come to mind for criticism:

It tries to do too much

14 special cases for special purpose gradients? Each of which interpret the actual parameters slightly differently? And it isn’t even an enumeration- it’s just a flat Integer value. To be fair to my former self I think I originally wrote it in VB2 which didn’t have enumerations, but nonetheless, it would have been possible to use Constants.

Variables are poorly named

I don’t even know what have of these do. what is SA? LOOPS? objgood? the XT! Array? Why do some of them declare their type with a type declaration character, while others declare their type specifically?


I mean… come on. Really? This isn’t Commodore BASIC, we can create new functions. What was I thinking

In my defense, this was before I learned about Object Oriented programming concepts and really before I learned anything about good design. Of course if you asked me back then I would have said I was a “good programmer” but I think this stuff shows that I would have been a liar to do so. Furthermore, this leaves one thinking.

I like to think I’m a capable programmer, but when I see my old code like this I always consider otherwise. It is notable that more recent programs (Like BCSearch) are really only annoying now because of the technology I used (VB6) and a few minor design decisions. If anything, they are often over-engineered.

One interesting approach is to try to be working on something where your skill level is that low. The goal being that in ten years you can look back and go “man, I barely knew how to use X, but now I consider all those trouble points trivial considerations”. It let’s you know that you’ve progressed.

Have something to say about this post? Comment!