2011/5/3 Cédric Beust ♔ <ced...@beust.com>

>
>
>
> On Tue, May 3, 2011 at 4:16 AM, Kevin Wright <kev.lee.wri...@gmail.com>wrote:
>
>> There was a code style which stated null checks should have taken the
>>> form of if (null == variable) which coming from Java I said was
>>> unnecessary however it turns out that due to .net support for implicit
>>> casts there are some fringe cases where if (variable == null) will
>>> behave differently to if (null == variable) apparently. Most of the
>>> developers used if (variable == null) though in spite of the coding
>>> standard because it was more intuitive.
>>>
>>>
>> I think this originates with checks against literal values instead of
>> against null when using value instead of reference equality.
>>
>
> No, I think this comes from the fact that C++ allows assignments in
> expressions, therefore you can write:
>
> if (a = NULL) ...
>
> when you actually mean
>
> if (a == NULL) ...
>
> Reversing the arguments avoids this pitfall. Obviously, this is not
> necessary in Java.
>


ah-hah, yes, that old chestnut!

Why did anyone ever think that assignment should look so much like asserting
equality? It never fails to cause problems...



> --
> Cédric
>
>  --
> You received this message because you are subscribed to the Google Groups
> "The Java Posse" group.
> To post to this group, send email to javaposse@googlegroups.com.
> To unsubscribe from this group, send email to
> javaposse+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>



-- 
Kevin Wright

gtalk / msn : kev.lee.wri...@gmail.com
<kev.lee.wri...@gmail.com>mail: kevin.wri...@scalatechnology.com
vibe / skype: kev.lee.wright
quora: http://www.quora.com/Kevin-Wright
twitter: @thecoda

"My point today is that, if we wish to count lines of code, we should not
regard them as "lines produced" but as "lines spent": the current
conventional wisdom is so foolish as to book that count on the wrong side of
the ledger" ~ Dijkstra

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to javaposse@googlegroups.com.
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to