Coding Standards
Coding Standards
Peer-Review Quality Some companies have "peer code review" meetings every once
in a while where a programmer hands out printouts of whatever they've been working
on and then walk all their peers through it so they get the gist of what's going on. Most
programmers dread peer review because much of the code they whip out from day to
day is a bit embarrassing. Companies like peer review because it scares the programmers
into avoiding embarrassingly bad code. So Peer review quality code tends to be mostly
pretty good, but with occasional lapses that can be rationalized to an understanding
audience- "I was going to decompose that, but I didn't have time." " oh yes, ha ha, on
page 8 there're are some utterly awful looking functions I whipped out to fix that VM
leaking bug we had in May. I don't think it will port to the HP anyway. I think we're
going to make the summer intern re-write it." "I'm going to go through and write
documentation for that module and fix the variable names just as soon as I finish this
current project I'm just right on the verge of finishing. Real soon now. I promise. Stop
laughing at me!"
for(;P("\n"),R-;P("|"))for(e=C;e-;P("_"+(*u++/8)%2))P("| "+(*u/4)%2);
It's a full 24% faster, and it only took me a day." Efficiency is often cited. This impulse
seems to come up in meetings and lectures as well.
2
What's Impressive
Just for reference, here's the offical chart of what's impressive and what's not, as published by the
Opinionated Programmers Council headquarted in Geneva Switzerland.
• Code which works on many, but not all cases Not Impressive
• Nasty looking code which is a pain to read and debug Not Impressive
• Thoughtless code which took little time to write Not Impressive
• Fast code which doesn't work quite right Not Impressive
Stanford CS Standards
In a Lord of the Flies, uncivilized incarnation, many programmers will slip into No-One-Is-Ever-
Going-To-Look-At-This-Again style code. Whatever takes the least time to type. But that habit
doesn't translate well in real world where programs need to work, get maintained, etc. On the other
end of the spectrum here at Stanford, all we do is write, read, and think about code and how to
write it better. Even if rarely attained, we should at least hold out Publication Quality as an
interesting ideal to think about. Peer-Review quality might still get an "A". Mediocre looking code
which computes the right answer should get a "B". When writing code, at least be honest with
yourself about what level you are aiming for, and start early enough to have a reasonable chance of
succeeding.
In the "one pass" model, you try to write things well enought the first time with the goal that you
will never revisit most of it. Of course with the unpredictability of debugging and unplanned
design revisions, you will certainly revisit some parts of your program. But if you choose a
strategy of revising the whole thing later, then you will certainly need to relearn all of it, and that's
going to take much more time than putting in the extra effort to fix things up on the first writing.