Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
ddephor44466yServes you right, this is really ugly code.
Condition expressions without parentheses 💩
Ternary operator embedded in a condition expression 💩💩💩
Function calls in condition expressions 💩
Function calls with side effects in condition expressions ☠☠☠☠☠-
@ddephor function calls in conditions is bad? To what extend? Even getter methods? What about something like an array contains. Or stream expressions (in Java)
-
ddephor44466y@gitreflog You can never be sure about side effects and volatility of the result of the function. Additionally it's hard to debug. The more function calls per expression, the harder.
So I'd better not do it.
I know it's a common case, but it's better to find another way -
ddephor44466y@gitreflog I forgot one point. On complex condition expressions functions may or may not be called depending on the expression results.
With a simple getter it's not an issue, but if there are side effects you get undefined behaviour.
And I've seen many of those implementations over the years. Often it was intentional, but let's be honest, if there are more than 2 conditions it's not testable. -
@ddephor One thing: that is not undefined behaviour. It is very well defined and should work exactly like that
-
ddephor44466y@gitreflog The complexity grows fast in this case. And if it's too complex to document and test the code, you cannot call it defined behaviour.
-
ddephor44466y@gitreflog The complexity grows fast in this case. And if it's too complex to document and test the code, you cannot call it defined behaviour.
-
@ddephor Wrong. Undefined Behaviour means: the language specs have no information what should happen in this case. But, in 99.9% of languages (Java, Python, C, Javascript) the following is defined
return (a == b) && functionCall()
as equivalent to
if (a == b)
return functionCall()
else
return false -
ddephor44466y@gitreflog We're not talking about language specifications, it's about implementations.
-
@ddephor Defined behaviour is not about your implementation, it is whether or not a behaviour is defined in the language specification
Spent like 24h trying to figure out why the system does not work. It turns out I forgot to put ternary operator into parentheses. :///
rant
#fuckme