Do we really need const?

Jarrett Billingsley kb3ctd2 at yahoo.com
Mon Sep 17 06:43:34 PDT 2007


"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message 
news:fcl79k$18vu$1 at digitalmars.com...

> It seems from the discussion here the past week, there is no real 
> multithreading benefit to be had from const/invariant.  'Pure' is where 
> it's at for that.  So maybe we're just better off without the complexities 
> of const.  I've certainly gotten used to the lack of const in Python, so 
> why not in a C++-ish language?

I start to wonder how much of the "of COURSE we need const!" thinking comes 
from "if all you have is a hammer, everything starts looking like a nail." 
That is, I wonder how many people think we absolutely need const because 
they're so used to using it in C and C++.

Never having learned a const-correct language (started with various BASICs, 
then on to very rudimentary C++, then D, and also a bit of Java and C#), I 
simply don't see the overwhelming need.  Sure, there are a very few cases 
where const could be useful in my code for efficiency's sake, but I've never 
felt like I was missing any expressive power.  Furthermore, I have been 
bitten exactly once by something that theoretically could have been 
prevented by const.  It took me two minutes in the debugger to track down 
the problem.  I'd say that those two minutes were a much better tradeoff 
than the god-knows-how-long it'd take to write const and non-const overloads 
of who-knows-how-many functions. 





More information about the Digitalmars-d mailing list