I like how cout demonstrates the lameness of the whole C++ iostreams syntax. I'll have to remember that the next time an argument arises.
Why 1 && 2 == 2
31–40 of 58 posts
Re: Why 1 && 2 == 2
#32Re: Why 1 && 2 == 2
#33Re: Why 1 && 2 == 2
#34Worth it for the memoization (I guess that's not really a word?) in Ruby. Cool new operator I did not know about.
Just be careful with this in JavaScript, as the greater number of things that are falsy can bite you if you do `a = a || 10;`, which is a very common JS bug.
Re: Why 1 && 2 == 2
#35Earlier quoted context omitted.
Not putting a format specifier wouldn't cause a segfault.
[deleted]
printf("Hi", 45);
which will not segfault. If you meant printf(45);
Then you are absolutely correct, that would segfault on common machines.Re: Why 1 && 2 == 2
#36For Python, a common idiom is to do this: condition and truecase or falsecase See "Boolean operations" and "Conditional expressions": http://docs.python.org/3/reference/expressions.html#boolean-...
This idiom is however out of flavor, unless you need to support python 2.4. Nowadays you would do this: truecase if condition else falsecase
Personally, I prefer the brevity of the older syntax, but to each his own. However, I understand the "ternary" expression was added because the older syntax was error-prone:
http://mail.python.org/pipermail/python-dev/2005-September/0... http://www.python.org/dev/peps/pep-0308/
Re: Why 1 && 2 == 2
#37Re: Why 1 && 2 == 2
#38Once you understand short-circuit evaluation, it opens up certain coding tricks. The line "[operation] or [error condition]" will attempt the operation on the left. If it succeeds, the program continues on the next line, ignoring the part about the error condition. If it fails, the error condition will execute instead. This might be something like "open file or die". Likewise, "[operation] and [success condition]" wi…
Re: Why 1 && 2 == 2
#39For Python, a common idiom is to do this: condition and truecase or falsecase See "Boolean operations" and "Conditional expressions": http://docs.python.org/3/reference/expressions.html#boolean-...
Re: Why 1 && 2 == 2
#40Worth it for the memoization (I guess that's not really a word?) in Ruby. Cool new operator I did not know about.