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
-
msdsk3182299dWhenever I see something written like that I swear I take at least 2d6 points of psychic damage. Unless they're writing for some extremely limited hardware it costs nothing to put it into ifs and then you don't need to ponder upon how many colons you've gone through to remember which clause you are at. If there is more than one colon in your ternary you failed.
-
Lensflare17159299d@msdsk "if" won’t make it more readable. Subexpressions replaced by properly named variables will.
-
Hazarth9502298d@kiki I don't think that's correct.
for example, if I substitute A = true, B = true, C = true
then the original expression would return "y"
but your expression would return "x"
I think it should just be
A && C ? y : x
the value of B is irrelevant. If B is true, it's up to (A && !C) for x to occur and if B is false it's up to ~(A && C) for x to occur... so x can only occur if (A && !C) || ~(A && C). But ~(A && C) is true only if either A, C or both are false, so it already covers the case of (A && !C) where only C is false... so it can be further simplified to just ~(A && C) ? x : y... but then the ~ would be just extra to we drop that too to get (A && C) ? y : x
I hope I didn't miss something xD but I think this is correct -
msdsk3182298d@Lensflare
fair, though once I tried to write it down using an if it became absurdly obvious that it could be written by the simple ternary of A && C ? y : x just because the formatting made it visible at the first glance. So I guess both.
A && B && !C ? x : A && C ? y : x
rant