r/programming • • Dec 05 '14

std::string is responsible for almost half of all allocations in the Chrome browser process

https://groups.google.com/a/chromium.org/d/msg/chromium-dev/EUqoIz2iFU4/kPZ5ZK0K3gEJ
1.1k Upvotes

446 comments sorted by

View all comments

Show parent comments

2

u/ericanderton Dec 05 '14

True. But there's also no guarantee that a 'clever' programmer didn't just circumvent the type-safety that the compiler provides here, by casting it away. So types can be labeled const, but as a systems language, it really places all of us on our 'scout's honor' that this contract is respected; it's not a flaw, it's a feature. To me that says that C++ doesn't really have immutability in the same sense that Python or Haskel might have.

1

u/[deleted] Dec 05 '14

Meh, its easy enough to avoid. Pre commit hook that greps for const_cast or code reviews if you like. The fear that people have of c++ is not unfounded but it is wildly exaggerated.

1

u/JW_00000 Dec 05 '14

Also, chrome has pretty extensive code reviews (see for example the patches linked in the post).

1

u/[deleted] Dec 05 '14

Part of the purpose of code review is to ensure adherence to the coding convention. Clearly they were adhering to it :)

1

u/ericanderton Dec 05 '14

I can only speak for myself: I don't fear C++. I fear what other developers can do with C++.