Do we need a time-out in D evolution?

Bill Baxter dnewsgroup at billbaxter.com
Fri Jun 8 12:25:43 PDT 2007


Regan Heath wrote:
> eao197 Wrote:
>> On Fri, 08 Jun 2007 20:22:09 +0400, Carlos Santander  
>> <csantander619 at gmail.com> wrote:
>>
>>> I might be wrong, but I don't think Dv2 will be incompatible with Dv1 in  
>>> a major way. If you start coding now, perhaps you'll have to branch your  
>>> code to make use of the shiny new features of Dv2, but I don't foresee  
>>> many changes. Of course, I guess that depends on your actual code and  
>>> the features you want to use, but I still wouldn't be so worried.
>> I don't agree with you. As a C++ programmer I'm big fun of 'const' -- it  
>> have saved me from bugs several times. So when const became a part of D I  
>> certaintly rewrite my code with use of const/final/invariant. To show you  
>> how it can affect my project I can say -- in one my rather big C++ library  
>> (~46K lines) there are 121 *.hpp files with ~280 const methods and ~900  
>> const parameters. I think it is not too easy to write all that staff  
>> without const at first and then carefully rewrite and retest it with const.
> 
> Another reason for const by default with implicit 'in'.  If this was implemented then you wouldn't need to re-write anything to get the full benefit where function parameters are concerned.  You would need to add const to return values and method signatures, but that would be a lot less to add/recode.

Indeed.  If D 2.0 were default const, to make your code totally const 
correct would involve basically
while not compiled:
    try to compile
    fix compiler error about non-mutable parameter that should be mutable

With non-default const it will be more like
foreach function in entire codebase:
    read source code
    add 'in' to each parameter that looks unmodified


Hmm ...I guess you could just go through and manually add 'in' to every 
parameter everywhere as a first pass (or use a tool to do it), then use 
the first procedure above.

You know I wonder if in general using a tool (an IDE) could be a 
reasonable way to simulate const-by-default for those who want it. 
Smart IDEs already know when you're typing function parameter lists, and 
could be made to always stick in an 'in ' by default after every '(' and 
',', in the parameter list.  Then you'd have to hit backspace (once) to 
get rid of it if it's not what you want.

--bb



More information about the Digitalmars-d mailing list