Do we really need const?

Robert Fraser fraserofthenight at gmail.com
Mon Sep 17 13:22:37 PDT 2007


Jarrett Billingsley Wrote:

> "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. 
> 
> 

You put it a lot better than I did. High-five!



More information about the Digitalmars-d mailing list