I like constant correctness ... in theory. Every time I tried to put it into practice, it eventually broke, and const_cast starts crawling, making the code ugly.
Maybe it's just the design patterns that I use, but const always turns out to be too wide a brush.
For example, imagine a simple database engine ... it has schema objects, tables, fields, etc. A user may have a const table pointer, meaning they are not allowed to modify the table schema directly ... but what about manipulating the data associated with the table? If the Insert () method is marked as const, then it must discard the constant in order to actually manipulate the database. If it is not marked as const, it does not protect against calling the AddField method.
Perhaps the answer is to split the class based on constant requirements, but this tends to complicate the design more than I would like for the benefit it brings.
Rob Walker Sep 26 '08 at 0:01 2008-09-26 00:01
source share