K
Keith Thompson
Eric Laberge said:[etc.]Keith said:I recently read a very interesting essay by Ken Arnold, in the Joel
Spolsky's book "The Best Software Writing I". He advocates making
coding style part of the syntax of the programming language. (He's
talking about programming languages in general, not just C.) [example]
Programmers would quickly adapt, simply because they'd have to. You
don't hear complaints about C keywords being in lower case, because if
you try to use "IF" rather than "if" your code won't compile.
Likewise, if your code would no longer compile if you used a
non-standard layout, you'd quickly learn to conform.
The result: Not only would code be more consistent and easier to read,
but we'd stop wasting time arguing about where the braces go.
I think this is indeed a good idea, but I believe the *computer* should be
in charge of the coding style.
What I have in mind is something like the unix "indent" tool, with more
power/customization/a pretty configuration GUI and integrated in the design
environment or ran stand-alone before the code is uploaded to the revision
control system/repository/whatever and after it is downloaded from it.
This way, every coder can have his own coding style, and it will all look
the same for each other. This seems to me like it would be easy, just a
matter of parsing the code (keeping the comments) and rewriting it using
pre-defined or custom guidelines.
Of course, there would still be the need for comments and code documentation
standards, but this could eliminate style wars like
if (a == 0)
versus
if (0 == a)
or
if (condition) do_stuff();
versus
if (condition)
{
do_stuff();
}
Now feel free to totally crush this idea :^)
Ok. }
Sorry, but if we were to impose style as part of the syntax, I don't
see much benefit in allowing each programmer to write in a different
style. Just define a single style and enforce it. Smart text editors
can help a lot for programmers who want to use them; the programmer
can type his parentheses and braces anywhere he likes, and they'll
*immediately* be put in the right place. Personally, I don't use a
syntax-aware editor (beyond auto-indent); I'll just write the code
correctly in the first place.
This is as much about the programmer's mindset as he's writing the
code as it is about anything else. The point is to end the debate and
spend our time on more important things.
Of course, nobody is going to stop anybody from creating whatever
tools they like, as long as the end result is syntactically correct
source code. But *if* this idea were to catch on, there would be no
more reason to let each programmer have his own coding style than to
let each programmer have his own idea of how reserved words should be
spelled. It's easy enough to create a syntax-aware editor that
transforms "IF" to "if" and "ELSE" to "} else {", but nobody has
bothered to do so.
Surely placement of punctuation marks isn't the best way you can think
of to express your individuality and creativity.