One of the biggest advantages of programming in C++ is that you can do the same thing in a variety of ways. At least in theory the compiler lets you do this. Under these circumstances, the difference between a good programmer and a very good programmer lies in the methods they use to accomplish specific tasks. Coding with const correctness in mind is one of the recommended techniques that raises you to the level of a very good programmer. Itís that important to grasp this concept.
Const Correctness in C++ - Conclusion (Page 4 of 4 )
If you read my article about Coding standards you should already know what benefits it brings to your programming "kitchen." Const correctness promises to offer at least as many benefits if it is done right. You can get a code where the modification of every type can be tracked effortlessly.
But think it over; don't use const everywhere just because you can do it. Use it only where you are absolutely sure that no modification will be made. Write functions as generally as you can; if the function can have a const overload, make it. However, be aware of local variables and don't start returning const references/pointers to them; local variables are destroyed.
Only one question remains to be answered: when is it best to start implementing const capabilities in a program? The most accurate answer would be "before you start writing a single line." The functions in your head should be born with const correctness. It can be hard at the beginning (especially to not abuse it), but once you get it, it will became second nature, and spare you countless hours of debugging.
If you are still reading these lines that means you have reached the end of this article. Now the challenge begins. Start up your compiler and start using the knowledge amassed here. It won't be a trivial task, but if you ever run into problems you can ask the community at DevHardware Forums at any time.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.