Things that suck about C++ #1
29 comments · 12% upvoted · source · other discussions
29 comments · 12% upvoted · source · other discussions
How isn't that a common sense? What's next? are we gonna say that c++ is bad because 2 + 2 * 2 != 8? Learn precedence, where in doubt put parens. If you want to use these constructs compiler assumes you know what you are doing.
Great attitude mate. Why don't we just remove all compiler warnings and error messages then? After all the compiler assumes you know what you're doing, and you wouldn't possibly write a bug would you?
false-positive warnings for ?: will be too much and will pollute the output, static analysis is the way to go
Clang warns about it actually.
clang has this to say:
Warning:(368, 27) operator '?:' has lower precedence than '+'; '+' will be evaluated first"
so...
Things that suck about ignoring your compilation warnings #1
FTFY
I don't ignore compilation warnings arsehole. That's how I found the bug.
What compiler did you use?
I uses lots of different compilers. Clang is what found the bug.
I'm not sure I'd even use the ternary operator like that anyhow. That convolutes what the code is doing and really damages readability. I'd much rather have an if-else clause that makes the logic clear.
That said, operator precedence is a gotcha in every language, not just C++ and its weak type system is a trait of many other languages. So I'd say while this does suck, it's not really excessive to C++.
It's almost enough to know that multiplication & division takes precedence over add/subtract, pointer dereference is higher than multiplication. Just use parentheses for everything else and don't confuse people.
Bonus: ternary operator is confusing enough on it's own, using it inside expression is asking for trouble IHMO.
We’ve been trying to reach you about your car’s extended warranty
oh dear, someone is very upset.
this is scandalous!! scandalous i say!
Things that suck about C++ : I never bothered to learn the basics of the language.
Things that suck about C++ #1:
People who write blog posts about how bad C++ sucks for the last 15 years. Sorry but what does a reader gain from reading this??
Also that's not even C++ specific it's the same in C.
Ono-Sendai [OP] -11 points · Apr 2016
Things that suck about C++ #2: You can't say anything bad about it because it is old apparently.
bitbait 6 points · Apr 2016
It is like that in C ever since the ternary operator is around, so for the last 38 years. It has lower precedence than relational operators, logical operators, shifts etc.
How is it a reason that C++ sucks in 2016?
This operator and its precedence in C was around before most languages you're probably comparing it to even existed. I also totally fail to see how it's counter intuitive. It evaluates expressions. Clearly 10.0f + true is an expression so that's what's on the left side of the "?".
Ono-Sendai [OP] -3 points · Apr 2016
If you read my post at all carefully you will see I'm not complaining about the precedence. I'm complaining about the type conversions (bool to float) resulting in lack of type safety. This was a problem 38 years ago and is still a problem.
Edit: serves me right for writing a blog post with any complexity, most people won't read it carefully.
_georgesim_ 8 points · Apr 2016
The fact that you think your post had any complexity explains why you had this bug to begin with. Most reasonable people just accept the fact the ternary operator has a lower precedence or don't write code this shitty to begin with.
Spartan-S63 5 points · Apr 2016
Up vote for honesty. Pretty much the use of the ternary operator in the example is pretty poor and really hinders the readability of the code.
Ono-Sendai [OP] 0 points · Apr 2016
You do realise that's a made-up example right? The actual source code is private.
Spartan-S63 2 points · Apr 2016
If you're going to use a contrived example how is your criticism valid?
Ono-Sendai [OP] 1 points · Apr 2016
It's a simplified (vars renamed, expression simplified a bit) version of a real bug.
Spartan-S63 2 points · Apr 2016
Okay, so even if it's simplified, an inappropriate and convoluted use of the ternary operator was used. It's less a language issue and more of an issue of poor programming practices, in my opinion. The language enables it to happen but the programmer made a poor choice to use a feature like that that hinders readability.
load 0 more replies →
Ono-Sendai [OP] 0 points · Apr 2016
The post was sufficiently complex for people to misinterpret.
bitbait 4 points · Apr 2016
Of course you do and the fact that you think people don't "understand" what you're writing about or that you discovered something new or that something complex is happening here is sort of telling:
Then you go on and ramble about that this leads to what you call a "gross violation of any reasonable type system".
Well of course you can. But again how would you think it's any different? Bool is not excluded from promotions. In C++ a boolean value is converted to int with value 0 if it's false and to int with value 1 if it's true. All you're doing there is adding an int to a float value which of course is promoted to a float. Everything what happens here are the basic rules of C and C++ and I believe everybody who learns the language for a couple of weeks can answer your question
And again I fail to see how this is a reason that C++ sucks which is worth mentioning in 2016 sry. I don't blame you for writing the post but I don't find it useful, interesting, curious or anything else.
edit: Actually the other posts on your blog deal with way more complicated topics, no idea why you have a problem here
spectre_theory 4 points · Apr 2016
you're a moron
Ono-Sendai [OP] -2 points · Apr 2016
fuck you.
spectre_theory 2 points · Apr 2016
you want to write blog posts about programming? wash your mouth. do your parents know you're still up this late?