FWIW, I initially hated the && and || idiom (or "trick"), and thought it 
was utterly illegible and way too clever by far. 
But after a few months, I find myself using it all the time... The trick, 
in my opinion, is really not to think about it too much, but just read it 
out, mentally, to yourself, as Stefan said, as 
LHS && RHS -> "LHS holds *and then* evaluate RHS", or
LHS || RHS -> "LHS holds *or else* evaluate RHS".

Some examples from a recent routine:
gcd(x,y) > 1 && continue    # if gcd(x,y) > 1, then continue
mod(n,y) == zero(n) || continue   # mod(n,y) must equal zero, or else 
continue

So, I'm quite happy with that idiom for one-liners, and read it without 
thinking about it further. 
The 
if LHS then RHS
looks nifty, too, though. But is it worth an extra keyword? And then, for 
consistency's sakes, one ought to go through all the code and replace
LHS && RHS  -> if LHS then RHS, 
and furthermore (and somewhat uglier)
LHS || RHS   -> if !(LHS) then RHS

Not sure that's worth it... 
Documenting that Julia idiom seems like a worthy idea though. I've put a 
pull request here, pls have a look:
https://github.com/JuliaLang/julia/pull/6336

Reply via email to