Saturday, July 19, 2008

This Is Madness!

Jeff Atwood's Coding Horror had this little tidbit about a week ago.  I was intrigued, and went to the wiki for Spartan Programming and read up a bit.  Jeff comes out as more positive towards Spartan Programming than not.

It starts out well - the goal is to eliminate complexity, making the code as simple as possible.  They also seem to have an admirable aim to make sure that things are spelled correctly in code and comments - I can't recall how many times I've cringed because the previous programmer misspelled a word used as a variable all throughout a program.

They prefer the K&R coding style for its vertical compactness, which I disagree with, but that's a Holy War for another time.

They advocate pushing variables as far down in scope as possible, and eliminate the use of placeholder variables as much as possible.  Loops with foreach are preferred to for(;;) loops, etc.

And then they get flaky.  They contend that mere number of characters on a line increase complexity, and so they advocate using very short, even one character names for local variables, and parameters into functions.  This is counter to nearly all the information I've read on how people read - the added semantic information of a meaningful variable name makes code easier to understand, not harder. The next programmer will have a better time understanding the code if the interface has enough meaning to make the usage clear.  There is a small point of matching the domain usage - if writing a function to extract roots of quadratic equations, it's ok to use the common math terms, but I find it almost unbelievable that copy(char *s, char *d, int l) is considered significantly better than copy (char *source, char * dest, int length).

The wiki states that the term "Spartan Programming" was coined in 1996, which makes some sense to me - the author(s) had to have learned programming after the common C/C++ compilers had gained the longer identifiers.  I learned in the era when you had maybe 8 unique characters in an identifier, and I learned that having longer names was a blessing.

La plus la change, la plus la meme chose.  I expect to see someone soon campaigning for assembly as the best way to handle the excessive complexity of C.  With only 3 tokens per line, it is hard to beat!

Technorati Tags --
, , ,

No comments: