Monday, 29 December, 1997
This article originally appeared in Visual Developer Magazine, Feb/Mar 1998.
Have you ever seen source code that appears to have been written, not to solve a particular problem, but instead as an excuse to use some new language feature? Kind of a "here's a turbocharged pneumatic hammer, now give me something to whack" approach to programming. Never mind that a $2 screwdriver would have done the job better, more quickly, and without the $20,000 generator and other expensive equipment.
Of course, there's nothing especially cool or sexy about a $2 screwdriver.
I call this solution-looking-for-a-problem mentality "syntaxophilia"--a term coined by a good friend and co-worker. I've seen a lot if it lately, mostly from inexperienced programmers who've been reading too much about cool language features and not enough about solid engineering principles. Periodically you'll see an experienced programmer fall into this trap, but a simple whack upside the head will usually set him straight. The funny part (or it would be funny if I didn't have to deal with it every day) is that syntaxophiliacs see absolutely nothing wrong with their approach.
In fifteen years of programming computers for hire, I've seen a lot of strange things: COBOL that looks like assembly language, Pascal that looks like FORTRAN, BASIC that looks like spaghetti and, all too often, C++ that is absolutely indecipherable.
It's the last that worries me, because it's become so widespread. Hardly a day goes by when I don't hear, either at work or in an online discussion, a comment like "...and if we model it this way, then we can implement it using syntax feature X!" Invariably, "this way" is highly complicated and non-obvious, and "syntax feature X" is some language feature that the speaker read about the night before.
This is the mark of the syntaxophiliac. You can make positive identification if you rearrange the sentence: "...and because we want to use syntax feature X, we should model it this way," and observe the reaction. If the resulting discussion is about the benefits of syntax feature X rather than the benefits of the model, then congratulations: You've bagged a live one.
As much as I'd like to blame C++--a language whose entire design appears to be an exercise in syntaxophilia-for the problem, I can't. I've seen syntaxophilia exhibited in every programming language I've worked with. The real problem is that programmers-especially inexperienced programmers-like new things and will go to great lengths to justify their use of a new syntactic feature. An experienced programmer will look at the resulting design and say, correctly, "It won't work." He may even be able to articulate why it won't work. But he can't prove it! Unlike structural engineering, where the proper application of mathematics can prove the strength of a bridge design, there are no formulas by which we can measure a program design for correctness. The only proof available lies in attempting to build it.
So experienced programmers and technical leads are left with arguments that begin with "In my experience" and end with the syntaxophiliac walking away muttering obscenities about dinosaurs.
Terminal syntaxophilia (TS) is a disease that dooms a programmer to a lifetime of implementing cool new technologies in poorly-designed, buggy products that rarely see version 1.0-much less version 2. The only known cure is experience. After consistently failing while the dinosaurs consistently ship on time, reasonably bright syntaxophiliacs come to realize that we dinosaurs know a thing or two about developing software-one of which is that the proper time to use new language features is during the implementation phase, after a solid design has been completed.
TS: You catch it from yourself. And the cure is up to you.