logoalt Hacker News

const_cast05/08/20250 repliesview on HN

C++ is at least somewhat strictly typed and - again - most types cannot be null.

Make std::string null. You can’t. Make std::vector null. You can’t. It’s one of the benefits of a value types.

That, alone, eliminates a whole class of bugs that’s JS has. Yes, there’s edge cases in C++ too. The edge cases are the common cases in JS in this regard and that’s why I class them differently. Really, every language can do everything, basically. But how easy is it, and how common is it?

Also, for the record, using an initialized variable will result in a warning or compilation error.

None of this is to say that C++ does not have other glaring problems that JS does not. But, in my experience, it’s slightly more difficult to create logic bugs in C++. I also have worked with PHP - similar situation to JS. Too footgunny that in practice the codebase is riddled with bugs that rarely manifest, but are there. Everything you do has, like, a dozen implications and edge cases you need to consider.