Lars Wirzenius: Rant: Secrets of Successful Programmers
The Seven Secrets of Successful Programmers article was on
reddit today. I found it to be simplistic enough to be
inane. Also not particularly good advice in all parts.
For example, the article says that "[m]ost compilers will
strip the comments from the executable program". Strictly
speakig this is true: there is probably one or two compilers
out there that retain comments in the binary code they put
out. They're so rare, though, that it is quite utterly pointless
to say anything about it. Anyone who needs to be told that
comments don't impact performance or executable code size needs
a course in basic programming, not secrets about being
successful.
"A good indication that you have got the level of comment
right: could someone understand what your program does if
all but the comments were removed?" I disagree with this:
better advice would be "could someone understand the code if
you remove all the comments?" It's the code that gets
executed and so it is the code that should be used to
communicate and not comments, except when code can't be
made clear enough. For example: if you write a wrapper around
malloc to check that it succeeds, a comment explaining why
it is acceptable to just kill the application on failure
would be good, and very hard to express with code.
"In particular any code branch (an IF..THEN...ELSE
construction) and any code repetition (a WHILE...END WHILE
construction) should be indented so that it is easy to see
where they start and end." Gee, that surely is a big secret
that only successful programmers know about.
"Expect the unexpected and deal with it. Before you open
a file, make sure that the file is present." That's not a
good way to deal with it. It's a race condition just waiting
to blow in your face. The correct way is to attempt opening
a file and then deal with an error if it failed.
"Name your variables to aid readability. - - - The key is
to be consistent and to be as informative as possible." Packing
as much information as possible into a variable name can
be a hindrance to readability. Too many people read advice
like this given in well-meaning but misguided articles and
then go on to name loop variables nElementIndex.
The loop gets more readable if you name your loop
variable just plain
i. The loop variable is not
significant enough to warrant all the attention from a reader
that a long name requires. A short name in this context makes
it much faster and easier to glance at the loop and see what
it is doing.
Obviously names with scopes longer than a (fairly short)
loop need to be more descriptive.
Here's my seven secrets of being a successful programmer.
- Learn to worship the goddess of simplicity. KISS a lot. This is much harder than it seems: it's more difficult to be simple and good than to be complicated and adequate. Simplicity starts with the specification of the program or system, and needs to permeate the design, and the implementation, at every step.
- Pick good tools, and learn them well. You need to know many tools, and know them well, or you'll waste time on doing unecessary things. Tools include software programs, books, algorithms, data structures, and mental models. Learn editors, programming languages, Unix command line tools, and so on. Learn at least three different paradigms for programming.
- Learn how to learn and keep on learning. New stuff is invented daily, and you need to keep up with it, or you'll end up as useless as a COBOL programmer doing a web shop.
- Develop debugging muscles. This is perhaps the hardest thing to learn, since no-body seems to be teaching it. You'll be spending most of your time doing it.
- Learn how to do testing well. Unit tests, test driven development, black-box testing, integration testing, regression testing, test automation, ... There's lots of ways of reducing the likelyhood that code escapes your hands with bugs still in it. It will inevitably happen, but if you know what you do, you can be better than most everyone else. The industry standard for commercial, proprietary code seems to be around 20 to 30 bugs per thousand lines of code; the Linux kernel has less than 1, and is known as a cesspool of bug-infested muck, so surely you can do better?
- Learn to write prose well. Then write a lot. If you can't write a README, a manual page, or the specification for your next work project, who's going to know about your great programming?
- Oh, you need to learn how to program well as well, and that isn't so easy either. Knowing how to program well merely isn't enough to be a successful programmer.

Although its author Joe Hewitt cautions us to remember that Firebug is still an alpha release, I'd still recommend rushing to install it. If you're developing anything for the web browser this year, it's the most important tool you'll find. While it won't rid you of the problems of cross-browser compatibility, Firebug will speed you in uncovering the smelly bits of your web application.