preparing for const, final, and invariant

Charlie charlie.fats at gmail.com
Mon Jun 4 16:18:49 PDT 2007


I'm appalled, both that this is pretty much assured to be in D , and 
that the community seems to be behind it.  I thought that the reason 
Walter didn't want const was because of its added complexity , so 
instead he introduces _3_ new keywords ?  Does no one else feel like 
this is using a machine gun to kill a fly ?

I understand the need for immutable data when writing libraries, but 
'scope const final MyClass myInstance' ?!?  Theres got to be a better way.

I know this sounds over-dramatic, but if this is the direction D is 
headed, then count me out.  I loved D because if its elegant and 
powerful simplicity, I think D has strayed way to far from its original 
goal.

If anyone feels like _this_ implementation for const ( not the 
usefulness of const mind you ) is not for D, then please speak up or we 
all might end up losing our favorite language.

Charlie

Walter Bright wrote:
> This is coming for the D 2.0 beta, and it will need some source code 
> changes. Specifically, for function parameters that are arrays or 
> pointers, start using 'in' for them.
> 
> 'in' will mean 'scope const final', which means:
> 
> final - the parameter will not be reassigned within the function
> const - the function will not attempt to change the contents of what is 
> referred to
> scope - the function will not keep a reference to the parameter's data 
> that will persist beyond the scope of the function
> 
> For example:
> 
> int[] g;
> 
> void foo(in int[] a)
> {
>     a = [1,2];    // error, a is final
>     a[1] = 2;   // error, a is const
>     g = a;    // error, a is scope
> }
> 
> Do not use 'in' if you wish to do any of these operations on a 
> parameter. Using 'in' has no useful effect on D 1.0 code, so it'll be 
> backwards compatible.
> 
> Adding in all those 'in's is tedious, as I'm finding out :-(, but I 
> think the results will be worth the effort.



More information about the Digitalmars-d-announce mailing list