3 ms·
"I am a full const nazi nowadays, and I chide any programmer that doesn’t const every variable and parameter that can be." Immutability...one less thing to wor
by melling 14y ago
"I am a full const nazi nowadays, and I chide any programmer that doesn’t const every variable and parameter that can be."
Immutability...one less thing to worry about.
- ajross 14y agoYes, but it's easy to spend way too much time chasing that stuff, too. The API you're working with may not itself be const-clean, so you end up with a zillion const_cast expressions translating your "cleanly consted" local expressions into something the compiler will accept. And all that junk hurts maintainability and readability; you end up being tempted into nonsense like "caching" your non-const handle just to avoid all the casts, etc... Broadly, my feeling is that getting your own APIs (internal and external) to be const correct is important and worth the trouble. But don't jump through hoops to shoehorn the strategy into someone else's code where it isn't honored.
- aardvark179 14y agoI think that highlights a broader point that is touched on by the article. The Doom 3 code is not idiomatic C++ the way many would think of it but it does build its own consistent idioms and sticks with them wherever reasonable. It can do this through having a fairly small number of points where it touches the external world and ensuring that its idioms are compatible with that world. If you're building a program in any language and it interacts heavily with a particular library then you'd better write something idiomatic to that library. If you're going to be using several libraries (including your language's standard lib) with different idioms then one of the most important design decisions you can make is how to bridge them, and where to make compromises.