Const (computer programming): Difference between revisions

Content deleted Content added
m {{compu-lang-stub}}
+mutable keyword. might deserve its own article, but for now its here
Line 1:
'''Const correctness''' is a programming language feature, its most famous implementor being [[C plus plus programming language|C++]]. In languages supporting this feature, variables can be said to be 'const'. When a const object is referenced, only the methods declared as const may be called. This allows programmers to formalise a specific [[design by contract|design contract]]: they can promise at compile-time that a parameter of a function cannot be modified destructively.
 
Of course, const methods can only call other const methods, and cannot assign [[field (computer science)|member variables]].
 
In C++, a member variable declared with the ''mutable'' keyword can be modified when the method or even the entire class is const. This can be used to maintain internal data that needs to change even in const objects, such as in [[Reference counting|reference counting]] and [[cache|caching]].
 
{{compu-lang-stub}}