Modern C++ Won't Save Us (2019)
alexgaynor.net
Modern C++ Won't Save Us (2019)
1–10 of 266 posts
Re: Modern C++ Won't Save Us (2019)
#2The whole point of an optional type is to prevent accidental unchecked access to the value. Sure, sometimes it's useful for performance to skip the check when it's already known-safe from the context, but such dangerous optimization should have been behind a method like `beware_of_the_nasal_demons()`, not an innocent-looking convenience syntax for flirting with the UB — in a language that was supposed to be cleaning up the unsafety.
Re: Modern C++ Won't Save Us (2019)
#3Modern C++ Won't Save Us - https://news.ycombinator.com/item?id=19723066 - April 2019 (388 comments)
Modern C++ Won't Save Us - https://news.ycombinator.com/item?id=19714204 - April 2019 (1 comment)
Re: Modern C++ Won't Save Us (2019)
#4Re: Modern C++ Won't Save Us (2019)
#5Re: Modern C++ Won't Save Us (2019)
#6UB-invoking dereference in std::optional is such a baffling design choice. The whole point of an optional type is to prevent accidental unchecked access to the value. Sure, sometimes it's useful for performance to skip the check when it's already known-safe from the context, but such dangerous optimization should have been behind a method like `beware_of_the_nasal_demons()`, not an innocent-looking convenience syntax…
You might argue it should be that, but it wasn't my impression that it is that. My impression was std::optional is just there to allow for representing the absence of a value. Ideally that should be zero-overhead, which means dereferencing it should degenerate into a normal object access. Hence the current design.
Re: Modern C++ Won't Save Us (2019)
#7Re: Modern C++ Won't Save Us (2019)
#8Um... no. Not every (or even most) existing large C/C++ codebase should be migrated to another language.
"But security vulnerabilities! And crashes!" I admit all that. But a program can be useful and therefore valuable, even if it crashes at times. Rewriting the program adds value only by removing crashes and exploitability. In many cases, that's effort that could be spent in more valuable ways.
Re: Modern C++ Won't Save Us (2019)
#9Re: Modern C++ Won't Save Us (2019)
#10> There are significant challenges to migrating existing, large, C and C++ codebases to a different language – no one can deny this. Nonetheless, the question simply must be how we can accomplish it, rather than if we should try. Um... no. Not every (or even most ) existing large C/C++ codebase should be migrated to another language. "But security vulnerabilities! And crashes!" I admit all that. But a program can be…