[–] mueslix 8y ago ↗ A fairly short answer: code readability.People seem to try to write their code as compact as possible, not realizing that they usually only write a piece of code once, but they and others will have to decipher and make sense of it a dozen times in the near future. [–] thamizhan2611 8y ago ↗ I agree, when the logic is very complicated to be represented in a line of code. [–] pcvarmint 8y ago ↗ (I use "conditional expression" in place of "ternary operator" here.)I have no idea why GoLang doesn't have conditional expressions.I find a conditional expression to be much easier to parse than if-else statements.If it's too hard to read, then why is LISP written almost totally as expressions, and is still considered viable? a ? b ? c : d : e is much easier for me to read and understand than if (a) { if (b) { r = c; } else { r = d; } } else { r = e; } GoLang is supposed to be designed to remove "boilerplate code" and reduce code size, so I don't know why it doesn't have conditional expressions.Without conditional expressions, C++11 (but not C++14 and later) constexpr functions wouldn't be Turing-complete. [–] kazinator 8y ago ↗ Lisp is unambiguous, whereas: x = a ? b : c; Oops; that assigns x = a, and tests it. Not if that = is that of an initializer, though: int x = a ? : b : c; so now we have an expression that changes meaning if we have to split the initialization off into an assignment.You're often better off if you put it behind a macro: #define IF(X, Y, Z) ((X) ? (Y) : (Z)) In C coding, a lot of ternary action happens behind the curtain of preprocessing, where expression is almost fully parenthesized. [–] pcvarmint 8y ago ↗ C non-sequitor. Assignment is always lower in precedence than conditional expressions.CPP macros is red herring.
[–] thamizhan2611 8y ago ↗ I agree, when the logic is very complicated to be represented in a line of code. [–] pcvarmint 8y ago ↗ (I use "conditional expression" in place of "ternary operator" here.)I have no idea why GoLang doesn't have conditional expressions.I find a conditional expression to be much easier to parse than if-else statements.If it's too hard to read, then why is LISP written almost totally as expressions, and is still considered viable? a ? b ? c : d : e is much easier for me to read and understand than if (a) { if (b) { r = c; } else { r = d; } } else { r = e; } GoLang is supposed to be designed to remove "boilerplate code" and reduce code size, so I don't know why it doesn't have conditional expressions.Without conditional expressions, C++11 (but not C++14 and later) constexpr functions wouldn't be Turing-complete. [–] kazinator 8y ago ↗ Lisp is unambiguous, whereas: x = a ? b : c; Oops; that assigns x = a, and tests it. Not if that = is that of an initializer, though: int x = a ? : b : c; so now we have an expression that changes meaning if we have to split the initialization off into an assignment.You're often better off if you put it behind a macro: #define IF(X, Y, Z) ((X) ? (Y) : (Z)) In C coding, a lot of ternary action happens behind the curtain of preprocessing, where expression is almost fully parenthesized. [–] pcvarmint 8y ago ↗ C non-sequitor. Assignment is always lower in precedence than conditional expressions.CPP macros is red herring.
[–] pcvarmint 8y ago ↗ (I use "conditional expression" in place of "ternary operator" here.)I have no idea why GoLang doesn't have conditional expressions.I find a conditional expression to be much easier to parse than if-else statements.If it's too hard to read, then why is LISP written almost totally as expressions, and is still considered viable? a ? b ? c : d : e is much easier for me to read and understand than if (a) { if (b) { r = c; } else { r = d; } } else { r = e; } GoLang is supposed to be designed to remove "boilerplate code" and reduce code size, so I don't know why it doesn't have conditional expressions.Without conditional expressions, C++11 (but not C++14 and later) constexpr functions wouldn't be Turing-complete. [–] kazinator 8y ago ↗ Lisp is unambiguous, whereas: x = a ? b : c; Oops; that assigns x = a, and tests it. Not if that = is that of an initializer, though: int x = a ? : b : c; so now we have an expression that changes meaning if we have to split the initialization off into an assignment.You're often better off if you put it behind a macro: #define IF(X, Y, Z) ((X) ? (Y) : (Z)) In C coding, a lot of ternary action happens behind the curtain of preprocessing, where expression is almost fully parenthesized. [–] pcvarmint 8y ago ↗ C non-sequitor. Assignment is always lower in precedence than conditional expressions.CPP macros is red herring.
[–] kazinator 8y ago ↗ Lisp is unambiguous, whereas: x = a ? b : c; Oops; that assigns x = a, and tests it. Not if that = is that of an initializer, though: int x = a ? : b : c; so now we have an expression that changes meaning if we have to split the initialization off into an assignment.You're often better off if you put it behind a macro: #define IF(X, Y, Z) ((X) ? (Y) : (Z)) In C coding, a lot of ternary action happens behind the curtain of preprocessing, where expression is almost fully parenthesized. [–] pcvarmint 8y ago ↗ C non-sequitor. Assignment is always lower in precedence than conditional expressions.CPP macros is red herring.
[–] pcvarmint 8y ago ↗ C non-sequitor. Assignment is always lower in precedence than conditional expressions.CPP macros is red herring.
5 comments
[ 3.5 ms ] story [ 20.2 ms ] threadPeople seem to try to write their code as compact as possible, not realizing that they usually only write a piece of code once, but they and others will have to decipher and make sense of it a dozen times in the near future.
I have no idea why GoLang doesn't have conditional expressions.
I find a conditional expression to be much easier to parse than if-else statements.
If it's too hard to read, then why is LISP written almost totally as expressions, and is still considered viable?
is much easier for me to read and understand than GoLang is supposed to be designed to remove "boilerplate code" and reduce code size, so I don't know why it doesn't have conditional expressions.Without conditional expressions, C++11 (but not C++14 and later) constexpr functions wouldn't be Turing-complete.
You're often better off if you put it behind a macro:
In C coding, a lot of ternary action happens behind the curtain of preprocessing, where expression is almost fully parenthesized.CPP macros is red herring.