Sam Gentle.com

A return to form

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.
Edsger Dijkstra

Most programmers, even very good programmers, start by writing terrible code. Dijkstra called BASIC programmers "mentally mutilated"; he may have been thinking of the code I would someday write as a beginner. I hadn't ever heard of indentation, so I didn't use it. Subroutines scared me, so I just put all my code in one giant file. I didn't know how to make the body of an IF statement more than one line, so when I needed more lines... I just used more IFs. Needless to say, my code was a Lovecraftian horror I could barely understand even as I was writing it.

These days I've got if statements pretty well under control, and my first instinct when talking to a beginner programmer is to save them from the mental mutilation I inflicted on myself. Learn the form! Learn indentation and style! Learn code structure and comments and tests! Learn from my mistakes, young pup. Respect my long grey beard and glittering eye. Listen to my grizzled warnings, lest ye find yerself becalmed in a sea of spaghetti.

But the thing is, it wasn't all bad. At the time I was too new to understand that anything was wrong. My ambition hadn't yet scaled up to the point where it mattered whether my code was readable; I was happy if I could just get it to print some stuff. In fact, my ignorance was a source of great joy, because it made knowledge that much sweeter. When I found out about indentation, it was like an epiphany. Wow, I can understand code after I've written it! By having the chance to do things the wrong way, it made me appreciate the right way on a visceral level.

The problem with learning the right way first, then, is that it's arbitrary. You learn the form, sure, but you don't know why the form exists. I mean, sure, someone can handwave at you and say "badly-structured code is a nightmare", but until you've run out of single-letter variable names you won't really understand what "nightmare" means. It's hard to be motivated by someone else's assurances that this is the right way when it doesn't feel any different from the wrong way.

On the other hand, it's obvious that learning the right way is more efficient. We don't teach athletes to run badly before we teach them to run well. We don't teach gymnasts to do shoddy backflips with bad form and then hope they eventually come to understand why good ones are important. What a waste of time! Just teach them the right way from the beginning and they'll figure out why it was right when they win. I think this is roughly the attitude we use with beginners as well, and it does make some kind of sense.

But athletics and gymnastics aren't for everyone. For starters, a very small number of very motivated people manage to get very far in either. These people aren't motivation-constrained, they're skill-constrained. There's enormous time pressure; you've got about 10 years to win your medals and then that's it, so no room for screwing around. Most of all, you're facing off against other people who can out-compete you, so any inefficiency is a weakness your competition may not have. Plus these disciplines have been around a long time, and the form is pretty settled at this point.

And that last aspect, the lack of a settled form, is something that I think is worth considering. By learning the form without understanding where it came from, without getting a visceral understanding of the problems it solves, it makes it difficult to stray off the path of your existing knowledge. What if you need new form? What if there's a situation where the old form isn't relevant? Or what if you think you have a good reason to stop using the form, but really you just didn't understand it?

So, sure, if you're a professional athlete, or if you're trying to go from zero to a software development job in six months, learn the form. It'll be less fun, but you're not here to have fun, you're here to win. On the other hand, if you have the time, if this is a passion thing where you want to optimise for motivation, or if you're in this for the long haul and you want to end up with the long grey beard, glittering eye, and mental mutilation of hard-won experience, maybe it's not so bad to do it the wrong way first.

If nothing else, it'll rapidly reduce your desire to do it the wrong way in future.