Source formatters -- not the "right" solution
Jeffrey E. F. Friedl
jeff at unh.UUCP
Fri Dec 23 12:05:31 AEST 1988
Just a thought or two (or three...) on coding styles and such....
It seems to me that the idea of having a super-duper source-formatter
as a "solution" to the problem of having to work with code written in a
horrible style (i.e. any style not your own) is missing the mark (whatever
"the mark" is). I think that it helps ease a symptom without curing the
disease. Here are a few points I'd like to make:
- One problem with using a formatter was cited in an earlier posting
and I agree with it completely: leave style to programmers -- they
(should) know what they're doing more than any program. Sometimes,
creative indentation/etc can be used to make more clear a particularly
odd section of code.
- I would think, for most people, the style they use now is predominately
influenced by the style they used when they learned C (or their first
structured language). This is the case with me for many stylistic
points.
For example, I prefer to put the "{" of a new block on a line by itself
at the same indentation level as the for/while/whatever to which it belongs.
I can give lots of reasons why it's better than putting it at the end
of the for/while/whatever line. On the other hand, if I had learned
to program "the other way", I'd give reasons supporting that. Many of
the arguments would be the same in either case (i.e. "It looks more
natural"). What it comes down to is that what is natural _to me_ is
more natural _for me_.
- I feel very comfortable with my style, but I'm not afraid to change.
If one can show me why a different style is better on some particular
point, and if those reasons are enough to overpower both my reasons
for doing it the way I currently do and those feelings of what is
"natural", then I'll change. This happened numerous times when I
began programming years ago. It still happens now, but less frequently.
- A formatter would be difficult [(-:] to run on published (books, mags,
etc) code.
- I would guess that most people can read and understand code written
in their own style more readily than code written in some other style.
This is most certainly the case with me. However, for most
stylistic concerns, there are usually several "common" practices.
Once I realize that the code I'm reading is different from mine, but
uses other common practices, I have little problem following the code
(I should say, few problems resulting from the style.)
The hard stuff is when looking at really wild stuff such as student code.
Sometimes I think that they think indentation is a function of rand().
- "My style" is made mostly of various selections from the "common"
practices on the many points of style. If they happen to be the same
ones you have chosen, then you'd love my style. If not, maybe not.
The thing is that the average competent C programmer should be able
to read it without much difficulty. If not, then I'm the one who's
not being "average". If I found that 51% of mature programmers hated
my style and found it difficult to read, then I'd change. As a mature
programmer (I may be begging the question here [(-:]) with a
responsibility to my profession, I can/should learn to be understood.
At first it wouldn't be natural, but with time most any sane style can
become "natural".
I don't think that "the problem" will ever be "solved". Like I said above,
people like what they learn. What is needed is a book on style that everyone
agrees is wonderful and that every new C programmer learns and loves. Once
we all die out, they'll all have a common style. Excuse the pun, but I don't
think we'll live to see the day.
What could be done is (oh boy, Yet Another Bright Idea): a questionnaire
could be made addressing various points of style. From responses, one
could publish _Style_Today_, a book citing what _is_ used today. Not why,
or what should be used, but what _is_. Then we could all see where we stand
and go from there (or stay where we are -- whatever).
*jeff*
------------------------------------------------------------------------------
Jeffrey Eric Francis Friedl Box 2173 Babcock House
..!{uunet,decvax}!unh!jeff Durham, New Hampshire 03824
If you have a C.S. job opening in/near Kobe, Japan, tell me! I'll take it!
More information about the Comp.lang.c
mailing list