On Friday, 21 March 2014 21:54:53 UTC+1, Stefan Karpinski wrote:
>
> On the other hand, saying "4 == 2 + 2 or go home" is perfectly reasonable 
> ;-)
>

I like the && and || trick - hadn't seen it before and it's quite neat that 
it just happens to work due to the language design! *But* the || was 
actually more confusing than && for me, because the "English" translation 
of it reads like an exclusive or. Which it isn't. Except that it works like 
one because of short-circuiting. It confuses in a way not unlike using 
double negation.

So for the sake of people who just are starting out and still have to get 
used to this Boolean logic thing, if the documentation is going to mention 
this trick, I think it's very important that it very clearly explains how 
and why it works. Because you don't want people to walk away with a 
half-assed understanding of what's going on.

To play the devil's advocate some more: if-statements that start as 
one-liners tend to expand to do more stuff as the code is updated and grows 
in complexity. Go, for example, has mandatory curly braces around if 
statements for this reason: to avoid ambiguity and leave less room for 
mistakes when updating the code later. This could be an argument against 
the proposed "then" keyword for one-liners.

Reply via email to