luserXtrog said:
CBFalconer <
[email protected]> writes:
[...] I in over 20 years of programming I
have never known anyone use it for that use in C.
while ((EOF != (ch = getc(f))) && ('\n' != ch));
is better but still horrible. You have a habit or tendency to convolute
your code. This is C. C can and should be concise.
Platitudes and truisms.
while (((ch=getc(f))!=EOF)&&(ch!='\n'));
Is even clearer and reads properly left to right. I find it particularly
amusing that your pathetic defence of the " CONST == var" style is to
defend against "accidentally" using "=" instead of "==" and yet you
still fucked it up. Nice one. A real achievement.
We recently had quite a lengthy skirmish about this very issue.
The trend was unanimously against the zero-length statement
(nothing between the ')' and the ';') because of the statement's
syntactic significance.
Silence != consent. I am very happy to discuss ways to make the
statement controlled by the while more visible, but that does not mean
I am arguing in favour! This may seem odd, but a lot of energy can be
expended on matters of style without reaching any sort of agreement so
I think it is better to calmly discuss the options; debate the pros
and cons and leave it at that. In the end, I usually go back to doing
what I did before.
My own preference tends toward a brief (possibly empty) comment,
perhaps:
while ((EOF != (ch = getc(f))) && ('\n' != ch)) /*eat till \n*/;
or even:
while ((EOF != (ch = getc(f))) && ('\n' != ch)) 0x2E0L;
Well, that last one illustrates the whole problem. Anything you do
over an above what the syntax requires is arbitrary. If you like
while (C) {}, why not while (C) {{{}}}? Surely even more visible is
better than slightly visible?
[BTW you might no have noticed that you don't need a hex constant.
2E0L is a valid floating point constant!]
This motivates my own preference for minimal, and that includes the
brackets that everyone has so far left alone. I'd write:
while ((ch = getc(f)) != '\n' && ch != EOF);
I think the '\n' test is the more important one, so I would want to
bring it forward. I don't think spaces impede reading (I think they
help) so I never use minimal spaces, but superfluous brackets get in
the way. If anyone disagrees with this, I am very happy to listen,
but I doubt I would want to argue my corner, any more than I am likely
to change my preference.