2 ms·
1) Memory safety is practically zero-cost in languages like C++ or rust if you disable runtime bounds-checking (which the C++ standard library does by default).
by unscaled 11y ago
1) Memory safety is practically zero-cost in languages like C++ or rust if you disable runtime bounds-checking (which the C++ standard library does by default). You don't get 100% safety, but it's still leaps and bounds better than what the C standard library provide (a foot to shoot yourself in the gun with).
You may be that legendary programmer who writes code "without bugs" and everything works correctly on the first run. I don't doubt a handful of "real programmers" like that exist. But most of us make mistakes, and we want the compiler to protect us. Just look at the endless stream of memory-related vulnerabilities at CERT. Nearly all of them could have been prevented in a memory-safe language.
2) That is a non-issue. All serious standard libraries define operation complexity at the Big O granularity. Sometimes they go even further and the spec (especially in C++'s case) gurantees some implementation details.
Anyway, if you're not happy with the proper characteristic of a standard data structure for a certain use, there's nothing preventing you from creating your own data structure with your preferred behavior pattern. You can even use an 'unsafe' override - at least you'd isolate unsafety to a very small and manageable part of the code that way.
3) Again, nothing prevents you from optimizing for special cases. But that are many more programs (e.g. parsers) that deal with short and repetetive strings which can benefit from an implementation that passes them as value-types on the stack (this is essentially which most C++ implementations do).
4. I'm all for a default unicode string type and a separate "raw bytes" type. But the you should either store the string as unicode codepoints (UTF-32) or as UTF-8. UTF-16 is pure evil, since then people tend to assume UTF-16 elements are codepoints and surrogates break spectacularly.
- geocar 11y agoSure I create bugs, but they're not usually memory-buffer/overflow/underflow bugs: Those I was able to eliminate a couple decades ago simply by adopting some habits. Most of the bugs I create seem to have to do with my limited memory: I forget things when I scroll, or (more often) I misremember things. These bugs are still very embarrassing, but are something I'm working on by scrolling less. Re 2) I agree it should be a non-issue, but the parent wanted to make the implementation fully opaque which hides operation complexity. Re 3, 4) Agreed completely. I think these are easier to get with increased flexibility, not with stronger harnesses though.