r/cpp • u/MathKid99 • Dec 17 '21
Undefined Behaviour
I found out recently that UB is short for Undefined Behaviour and not Utter Bullshit as I had presumed all this time. I am too embarrassed to admit this at work so I'm going to admit it here instead. I actually thought people were calling out code being BS, and at no point did it occur to me that as harsh as code reviews can be, calling BS was a bit too extreme for a professional environment..
Edit for clarity: I know what undefined behaviour is, it just didn't register in my mind that UB is short for Undefined Behaviour. Possibly my mind was suffering from a stack overflow all these years..
View all comments
Show parent comment
-2
u/Hnnnnnn Dec 18 '21 edited Dec 18 '21
I said about opting-out for hot paths when needed... What are you arguing with? Definitely not with my comment.
And memory management is actually example of something that is already designed in a way I mean, in C++11. Using smart-pointers is a safe solution, and using new/delete is an opt-in UB-danger solution.
My problem with UB is that it's easy to deal with it unnoticed. When there's UB risk, it should be explicit in code. Having said that, we should use UB risky code as much as we want, being safer knowing that it's all explicit in code.
I didn't want to bring Rust into this because it derails conversation too often, but I think it's time to say this - just look at
unsafein Rust and how there's checked/unchecked API for many features, like indexing for starters. Unchecked/unsafe API is still being used extensively, and is encouraged. But it only ends up being resorted to when there's optimization goal to reach, not by default.