Monday, March 31, 2008

Programming for Beginner


I saw this Linux Format Special promising beginners to program, among other things, web browser, text editor, news readers, and web servers. While those aren't really that hard and quite doable, I was rather skeptical that a beginner can do all this in the rather thin format the magazine promises.

It turns out that most of the programming projects is what I call "LEGO Programming". Cut and Paste. Drop in packages and libraries. While there's nothing wrong with LEGO Programming, it isn't something you say in the same breath as "a programming wizard."

Sorry to be harsh here, but using packages and libraries ranks below cutting and pasting code. Even cutting and pasting code is pretty low on the scale. So don't think just because you can use a "60 megabytes Microsoft Visual C# Express" suddenly makes you a programming wizard. I'm not saying you can't be a professional with it, just not a wizard. Actually, though, I've seen more "script kiddies" professionals than not. Probably due to the need of those technical school to pass on certificates to whoever walks thru the door.

I still remember the time when us computer programmers were men. And we were REAL men. We don't eat Quiche. And the women were ... Practically non-existent. Looking back at it, probably because we men were lacking and any potential target means we hit them hard and fast whenever one present herself. They don't last til next day, if they showed up at all. But hey, that what we men do.

Anyway, the thinking of a computer programmer is different than that of a designer. LEGO Coders merely built a program using existing pieces, but not something new. That's not computer programming! Take a look at this code (p. 66):

3 letters or letters or less = 0
between 4 and 5 = 3
between 6 and 8 = 5
between 8 and 12 = 7
more than 12 = 8

Any computer programmer can tell you that the specification is bad. So is 8 a 5 or a 7? The code makes it clear, but the specification needs rewrite.

if (pwd.length>3 && pwd.length<6) strength+=3
else if (pwd.length>5 && pwd.length<9) strength+=5
else if (pwd.length>7 && pwd.length<13) strength+=7
else if (pwd.length>12) strength+=8

You can see the overlapping ranges. Better is this way:

if (pwd.length>12) strength+=8
else if (pwd.length>=8) strength+=7
else if (pwd.length>=6) strength+=5
else if (pwd.length>=4) strength+=3

It's not rocket science. Simply by re-arranging the checks, we can clarify the logic tremendously and save computing cycles to boot. This is a common rookie mistake. I say rookie because it's not that hard and experience will eventually let the rookie know the efficient way to do things. That is computer programming.

No comments: