Answer by Casey for Optimize ternary operator
Common or recommended? No.I did something similar, but I had my reasons:It was an argument into a third-party C function.I was not well versed in modern C++ at the time.I commented and formatted the...
View ArticleAnswer by BЈовић for Optimize ternary operator
Others already said how awful that code excerpt is, with nice explanations. I will just provide few more reasons why that code is bad :if you consider one "if-else" to implement exactly one feature,...
View ArticleAnswer by Peter - Reinstate Monica for Optimize ternary operator
Perhaps this is in a device driver's message loop and the original coder, possibly 10 years ago, didn't want jumps in the code. I hope he verified that his compiler didn't implement the ternary...
View ArticleAnswer by Chase Henslee for Optimize ternary operator
What an ugly mess. I broke it out into if and else's just to see what it was doing. Not much more readable, but thought I'd post it anyways. Hopefully someone else has a more elegant solution for you....
View ArticleAnswer by Karoly Horvath for Optimize ternary operator
That's just horrible code.It's badly formatted. I don't see the hierarchy of the expression.Even if it had good formatting, the expression would be way too complex to quickly parse with the human...
View ArticleAnswer by 5gon12eder for Optimize ternary operator
This is terrible code.While it is often desirable to initialize a variable with a single expression (for example, so we can make it const), this is no excuse to write code like this. You can move the...
View ArticleOptimize ternary operator
I came across this code written by someone else. Is this usage of the conditional operator recommended or commonly used? I feel it is less maintainable - or is it just me? Is there any alternate way of...
View Article
More Pages to Explore .....