Now, I've never formally studied c++. It wasn't part of my education, and I learned it "on the job". I have tried to read and learn as I encountered things I didn't understand, and I like to think I know a lot of things about the language. I mean, I even got a gold tag badge for it on Stack Overflow. Surely I'm not completely ignorant. Right?
One of the talks I'm watching is highlighting some parts of the Core Guidelines. The presenter brings up a case that I actually faced recently.
- You have a class with a
const
accessor method that returns the result of a computations (i.e. is not accessing a feature of the current implementation but a feature of the model that can be deduced from stored elements of the implementation) - That deduction is expensive enough that you want to cache the result.
- You run into a conflict between the need to update the value of the cache and the desire to have the accessor marked
const
because it isn't changing any feature of the underlying model.
const
), but I did lose the const
marking on the accessor because I didn't know about mutable
.Crap.
Learn something every day.
No comments:
Post a Comment