What debate as is as vitriolic or virulent as one involving coding style? What subject more a flame inducing napalm? And when pride is on the line, what clash more titanic?
Yesterday, I was presenting a graph structure API indented for use as the model layer in a MVP style map visualizer. I’d spent the better part of December refining and reworking the approach until order was born of choice, consistency from confusion, simplicity from complexity. As a result, there were few complaints except a matter style.
“Why,” asks the Proud Programmer, “are you leaving out the space after method names?”
“Leaving out a space? Where?”
“Here for example,” says the Proud Programmer, “you wrote:
public Object put(Object key, double value);
“where the style guideline requires a space:
public Object put (Object key, double value);
“You always put a space after the method name if the method takes arguments.”
I am dumbfounded, “where did you come up with that? What style guideline? I’ve never seen it before?”
The Proud Programer retorts, “It’s the style for both Nomads and CmapTools.”
I reply, “that may be true. I’ve never worked on either of the projects. None of my projects do that; moreover, I’ve never seen it before. Where did you come up with it? The Java Book (Arnold, Gosling, and Holmes) has no space.”
The Proud Programmer calls on authority, “Surely you’re mistaken. The space is in the Java coding conventions. It goes back all the way to K&R.”
The Proud Programmer has gone too far. Now I’m liberal person. I believe man can do what he wants with is spaces, his tabs, and his curly braces. His spaces end where my curly braces begin, but I’m an accommodating person. When a guest in your blocks or your classes, I will live by your rule no matter how repugnant. But you have made mistake my proud friend. Invoking K&R is serious. K&R is scripture. Misrepresentation is blasphemy. Such offenses cannot go unchecked. Therefore, I am obliged to call, “No it doesn’t. It’s fine that you have your own style. But K&R don’t use a space.”
Proud Programmer is confident, “Of course it does.”
Too confident he is, “I’m sure it was the other way. Perhaps one of us has not reviewed K&R recently.”
With this, the meeting is over. No discussion can continue until matters of doctrine are settled. I go to my office. Check the Java book. Have I forgotten the way? No, no, I see the methods and there is no space. To the Proud Programmer’s office. He’s just opening K&R as I enter. He looks, again no space. He’s shocked, confused, he denies the truth though it’s right in front of his face. “Why do they do that? The arguments run together with the function name. That’s just wrong.” I show him the Java book. He doesn’t consider it authoritative. “What does this Gosling fellow know about Java? I’m sure the Java style guide as a space.”
I return to my office. Just to ensure that I’ll have the freedom from spaces in my own code, I look up the Code Conventions for the Java Programming Language hoping to trample all claims of authority. I’m luck. Page 15 of the PDF, “No space between a method name and the parenthesis ‘(’ starting its parameter list,” unequivocal vindication. I close my message, “So you see, I’m still curious where you came up with your conventions.”
This is an honest question. Orthodox or heretic, it’s all a matter of style. I may have precise preferences. But I can tell when I’m in the mainstream or a heretic headed upstream. Semicolons at the end of lines in
JavaScript, for example. I won’t have them, but that’s certainly not the received style as outlined by the Rhino book. (Not that the Rhino book can be truly authoritative. After all, it conflicts with K&R and Java on the point of spaces after for, while, and switch.)
Another example, I always put spaces around arithmetic operators and I never put spaces around string concatenate . I think the space improves readability for arithmetic. But ends up unwieldy for strings. Compare “(” + x + ”, ” + y + “)” and “(“+x”, “y“)”. As a nice side effect, one can tell without context, whether I mean strings or numbers. Though when given free choice, I’d prefer spicing. Of all the forms, my favorite is “({x}, {y})”. I don’t know where it comes from. I first encountered it with Factor.
Which brings us back to the question. Who uses space and why? Where does the practice come from? Though I had never seen it in Java, it is used in Lua. (Not that Lua’s syntax wins many beauty pageants. It does do well in the object literal competition and is simply marvelous when it comes to nested comments and here documents.) Likewise, it’s used in Lua’s source. So I imagine the space comes from some C practitioner though I’d like to know who.
Commentary