On Thu, Mar 20, 2014 at 7:24 PM, Cristóvão Duarte Sousa <[email protected]> wrote: > Although the short-circuit is more or less known among several programming > languages, I don't think it's that "readable" outside of an "if". > Maybe after a while one starts to read that code as "if then", but it's not > so straightforward to beginners reading someone else's code. > > But the question is answered: that's the julian way :)
I think this kind of short circuit evaluation is idiomatic in perl as well, as typified by the use of the die function https://www.cs.cf.ac.uk/Dave/PERL/node111.html Not that I think julia should take syntactical advice from perl ;-) IMHO it's pretty ok for error checking because the natural way that i == 1 || error("foobar!") reads forms a more or less valid English statement: "condition is true or error" On the other hand, I felt slightly embarrassed by the lack of clarity displayed in i == 1 && do_stuff() when I had to explain it to a matlab user a couple of days ago. Maybe the most readable alternative is just to include a semicolon (since we don't have a "then" keyword) and put up with the extra end: if i == 1; do_stuff() end That's not too bad I guess. ~Chris
