3 ms·
I like Yoda conditions not only because it protects against the missing "=", but also because often the constant is the shorter side, so reading if (42 ==
by hibbelig 13y ago
I like Yoda conditions not only because it protects against the missing "=", but also because often the constant is the shorter side, so reading
if (42 == some_long_expression_here)
{
...
}
It is immediately clear that the rest of the line after the two equals signs must be an expression because the curly brace in the beginning of the next line. So folks don't have to bother that much about counting parens.
- vittore 13y agoWell, you won't see 'magic values' in production code, or at least should minimize it