I like the idea of providing a nice syntax for one if statements but agree with Job van der Zwan about one-liners that grow. That comment immediately made me think of Apple's gotofail<http://news.cnet.com/8301-13579_3-57619510-37/apple-finally-fixes-gotofail-os-x-security-hole/>bug.
Maybe the inverse if statement, proposed above, is the way to go with this? do_stuff() if i == 1 On Saturday, 22 March 2014 19:35:11 UTC, Job van der Zwan wrote: > > 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. >
