use of if (!cptr) and if (cptr), where cptr is a *
George M. Sipe
george at rebel.UUCP
Mon Jul 24 01:34:41 AEST 1989
In article <37 at ark1.nswc.navy.mil> dpaulso at ark1.nswc.navy.mil writes:
>In article <14580 at dartvax.Dartmouth.EDU> ari at eleazar.dartmouth.edu (Ari Halberstadt) writes:
>>[...]
>> return(perror("it failed"), FALSE);
>>This saves the nuisance of using braces and two statements.
>
> I don't usually like to complain about other people's coding
>preferences, but this just struck a nerve.
>
> This is just plain ugly. When *I* see a comma operator, I tend to think
>of two things being done in parallel, so the impression I get when
You see it wrong thing then. What you should see are two sequential
operations. You are specifically assured of that.
As for ugly, perhaps a better word would be unfamiliar. I personally haven't
been (usually) coding that way, so it makes me think for a second when I see
it. In some ways its more expressive. In the right frame of mind it may
even be clearer.
It seems to me that the comma operator is one of those elements of C which
is not (at least) frequently seen in other languages, which fill a very
useful role. It's sort of like comparing:
some_very_long_variable_name = some_very_long_variable_name + 3;
vs.
some_very_long_variable_name += 3;
You don't have to do it the second way. You could say the second way is
ugly. You could argue that the first way is a "standard" method. Yet
the second approach many would say is clearer. There is no confusion
compared to the first approach where you would have to be careful that
the same variable was referenced:
some_very_long_variable_name = some_long_very_variable_name + 3;
With the expressiveness of +=, you immediately see what is happening.
I think the comma operator falls into that category as well, once you get
confortable with it.
--
George M. Sipe, Phone: (404) 447-4731
537 Lakeshore Drive, Berkeley Lake, GA 30136-3035
UUCP: ...!{decvax,linus,rutgers}!gatech!rebel!george
More information about the Comp.lang.c
mailing list