Do we really need const?

Robert Fraser fraserofthenight at gmail.com
Mon Sep 17 13:47:18 PDT 2007


Bruce Adams Wrote:
> The problem with this is it isn't easy to tell how many problems would have been prevented if you are a regular user of const because they've been prevented. One exercise to try would be to take a large project and replace const with an empty string and see what the code looks like, then count the number, type and severity of potential errors relating to this absence. The problem is that doesn't take into account the dynamic nature of programming. Far more mistakes occur during development than you might be able to find in a finished product.
> 
> 

I think this is a similar argument to the one used to argue that static typing prevents a lot of bugs that dynamic typing might introduce. Many people who have worked in a dynamically-typed language (even on a bigger project) will confess that the gain in productivity of not having to constantly specify interfaces, being able to "blindly" pass things around, etc., create a better cost-to-benefit ratio than static typing. In fact, it's the same argument used to justify checked/specified exceptions in Java.

The potential for a bug doesn't mean that that potential will be used, and the productivity benefits of NOT having const might be greater.

That strcpy thing _is_ a good example, though it won't catch that many bugs in its usage, since src already needs to be const. But it does show a valid use-case, which is better than I can provide for my argument ;-P.



More information about the Digitalmars-d mailing list