2 ms·
If / else is a way of defining what to be executed based on some condition. The ternary operator is used to guarantee assignment to a variable based on some co
by Too 14y ago
If / else is a way of defining what to be executed based on some condition.
The ternary operator is used to guarantee assignment to a variable based on some condition. It's not only a way to save space, it's a way to express your intent clearer. It simply doesn't leave any undefined code path behind.
In your case of changing the code a bit, in the carmack version of the function there's a risk that you remove the assignment to sides[i] in one case and it will later be undefined.
Though i agree that the syntax is horrendous since it requires you to remember exactly what the symbols ? and : do. Compare to the much nicer and to a newbie understandable python syntax: x = y if c else z