4 ms·
I find it readable if you're trying to test both sides of the && to be true -- if(foo() && bar()){ // do this } However, the way it's written in the article,
by WesleyJohnson 16y ago
I find it readable if you're trying to test both sides of the && to be true -- if(foo() && bar()){ // do this }
However, the way it's written in the article, the intent is to merely test foo() and then execute bar() if foo() returns true. Even though I'm familiar with &&, it took me a minute to understand this as well. I'd be eqaully annoyed seeing this in production code.
- scott_s 16y agoIt's a common idiom in many programming languages.
- JshWright 16y agoI'm with the GP on this one... Readable code is very important. Using the short-circuiting property of && doesn't decrease readability in most cases (unless someone isn't familiar with the language, or the concept of using short-circuiting for flow control).
- DrSprout 16y agoI've always found the Perl foo() or die(); idiom to be quite readable. And if you're familiar with that, this is a pretty straightforward extension.