Re: Code Comprehension
- From: Logan Shaw <lshaw-usenet@xxxxxxxxxxxxx>
- Date: Fri, 25 Aug 2006 07:20:37 GMT
Pascal Bourguignon wrote:
Logan Shaw <lshaw-usenet@xxxxxxxxxxxxx> writes:Pascal Bourguignon wrote:
My god! This is twice as hard to read! You do know that whitespace
is allowed in C, right? :-) No wait, forget the smiley. I'm
serious.
I've not observed that whitespace improves anything. On the
contrary, they may be misleading.
Of course it can be misleading. If you TRY to communicate badly,
you can certainly succeed. Or if you do not try but merely put
in whitespace randomly without regard to what it might indicate,
you can find yourself communicating badly as well. But that's
not a very good argument that whitespace can't be used to good
effect.
Yes, that still retains some C idioms, but you have to assume
some familiarity with the language. (I noticed even you did
that, because you did not eliminate the "for" loop, which is
deep in the C idiom, and replace it with a "while" loop.)
Things like the low precedence of "||" and the fact that 0 by
itself is a legal character constant aren't very complicated
and are hard to miss if you have much experience with C.
The point is that types are important to understand code, and if you
consistenly mislead the reader by using consistenly the wrong
operations for the type, you don't help readability.
It's not the wrong type. Anyone who is familiar with the basics
of C knows that '\0' and 0 are both integral values. So where
is the inconsistently? There is none. They are different
notations for basically the same thing. The only difference is
that a 0 by itself might have an integral type with a larger
range of values than the type of '\0', but since the value of
both falls in the range of all integral types in C, that doesn't
really matter.
I've also put the ";" on its own line to draw as much attention
as possible to the fact that the "for" loop has a null body.
Well that's one strong reason why to use while instead of for. But I
reserved a more violent end to that loop anyways, substituting it with
strchr.
Yes, that is a good argument to use a while loop. Not question
about that. However, with any loop that has an empty body, I
find it preferable to put the semicolon on the following line
just to emphasize it. Either that, or sometimes it works well
to use a pair of braces, like these:
for (c = str; *c != '4' && *c != 0; c++) { }
while (*(c++) != 0) { }
- Logan
.
- Follow-Ups:
- Re: Code Comprehension
- From: pete
- Re: Code Comprehension
- From: Rob Thorpe
- Re: Code Comprehension
- References:
- Code Comprehension
- From: jj
- Re: Code Comprehension
- From: Pascal Bourguignon
- Re: Code Comprehension
- From: Logan Shaw
- Re: Code Comprehension
- From: Pascal Bourguignon
- Code Comprehension
- Prev by Date: Re: Code Comprehension
- Next by Date: Re: Linked list problem (puzzle)
- Previous by thread: Re: Code Comprehension
- Next by thread: Re: Code Comprehension
- Index(es):
Relevant Pages
|