Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It wasn't marketing. When C++ took off as a language, such memory safety was a luxury. I've read Stroustrup's Design and Evolution of C++, and I don't think strict memory safety was even considered. Saying it was "excluded" implies that it was considered, when I think the kind of programming they wanted to support - systems programming with minimal performance overhead - precluded it from consideration.


Ada was a contemporary of C++ which had such memory safety. In fact Ada was first standardized long before C++, so the issue wasn't unknown or even obscure when C++ was being developed.

Moreover, there are no run-time performance issues. Memory safety can be verified at compile time provided things like pointer arithmetic are forbidden.

The problem for C++ is that memory safety and C-style pointer manipulation are incompatible.

C++ was marketed as "C with classes." This was a hugely successful marketing move (it helped C++ beat Ada, for one). It wouldn't have worked if all the C programmers keen on picking up "object orientation" had flipped open their C++ book and found that it had "neutered" their pointers though. They wanted to be "OO compliant" by writing "class" instead of "struct" and change nothing else and C++ promised to deliver that.


C++ was based on Stroustrup's early-1970s experience with Simula, where he was able to write a beautiful program (for his thesis research, I think?) that did exactly what he needed, but then discovered that doing the compute run he wanted to do would consume his department's entire computation-time budget on the mainframe. (Apparently 80% of the compute time was being spent in the garbage collector, even after he stopped allocating new objects, which sounds like a straight-up bug in the Simula runtime.) So he rewrote the program in BCPL, which is about like Forth except that it has infix notation and doesn't have metaprogramming.

So, some years later, in 1983, his key consideration in the design of C++ was efficiency — avoiding imposing any unnecessary overhead.

http://www.stanford.edu/class/cs106l/course-reader/Ch0_WhatI...

In the interim, although he didn't know this, generational garbage collection and inline method caches had been invented, which probably would have provided enough efficiency that he never would have had to switch to BCPL. (Actually, even a decently implemented early-70s Simula would have been five times faster, and that might have sufficed.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: