FROM : Scott Ribe
DATE : Mon May 26 21:35:30 2008
> I disagree with the whole notion that using the result of an assignment
> is "bad style" or "confusing".
I agree that it is perfectly clear. But there is still a serious problem
with it: it is too easy to make the typo of if(a=b) when one intended
if(a==b). This can be a surprisingly difficult typo to spot, when one is
staring at the code with the preconceived belief that one typed if(a==b).
There is no way for a compiler to warn one only on those instances where one
did *not* intend to type if(a=b), and that is why many people consider
if(a=b), if not actually "bad style", at least not worth the risk. I like
if(a=b), it's very C-like, as is if(myPtr). But I don't use it, because even
though I don't do that typo very often, it really just isn't worth it to not
be explicit.
The extra parentheses are just a convention that was adopted as a way to
tell the compiler that you really did want to make an assignment and test
the result in one expression. (I personally hate it, because I keep looking
for the "other stuff that should be in the parentheses"; I prefer just going
ahead and comparing to nil/NULL/0 as appropriate.)
> ...man serving machine, not the other way around as it should be.
Uhm, excuse me? I thought we were talking about C programming? Why would
there be any question about who is the master in this scenario?
;-)
--
Scott Ribe
<email_removed>
http://www.killerbytes.com/
(303) 722-0567 voice
DATE : Mon May 26 21:35:30 2008
> I disagree with the whole notion that using the result of an assignment
> is "bad style" or "confusing".
I agree that it is perfectly clear. But there is still a serious problem
with it: it is too easy to make the typo of if(a=b) when one intended
if(a==b). This can be a surprisingly difficult typo to spot, when one is
staring at the code with the preconceived belief that one typed if(a==b).
There is no way for a compiler to warn one only on those instances where one
did *not* intend to type if(a=b), and that is why many people consider
if(a=b), if not actually "bad style", at least not worth the risk. I like
if(a=b), it's very C-like, as is if(myPtr). But I don't use it, because even
though I don't do that typo very often, it really just isn't worth it to not
be explicit.
The extra parentheses are just a convention that was adopted as a way to
tell the compiler that you really did want to make an assignment and test
the result in one expression. (I personally hate it, because I keep looking
for the "other stuff that should be in the parentheses"; I prefer just going
ahead and comparing to nil/NULL/0 as appropriate.)
> ...man serving machine, not the other way around as it should be.
Uhm, excuse me? I thought we were talking about C programming? Why would
there be any question about who is the master in this scenario?
;-)
--
Scott Ribe
<email_removed>
http://www.killerbytes.com/
(303) 722-0567 voice






Cocoa mail archive

