What's missing to make D2 feature complete?

Daniel Murphy via Digitalmars-d digitalmars-d at puremagic.com
Wed Dec 24 02:32:35 PST 2014


"Ola Fosheim Grøstad" " wrote in message 
news:ggcloheiypsxdssfvwav at forum.dlang.org...

> Yes, but my point was that making all value parameters mutable is at odds 
> with correctness when you later edit it since you no longer know whether 
> it has been modified or not.
>

Modifying parameters usually falls into one of three classes: (in my code at 
least)
1. 'fixing' the value (eg removing invalid characters from a string, 
rounding)
2. reusing the variable
3. consuming the variable (eg popFront on a range)

3 can't be const/immutable, 2 should probably use different variables, but I 
don't have a problem with 1 being mutable.

> E.g.
>
> int myfunc(int n){
>      ...lotsofstuff...
>      x = mayormaynotchange(n);
>     ...lotsofstuff...
>     return n>0 ? x : 0;  // modified from "return x"
> }

I see this as more of an argument for avoiding long functions.  Marking 
every possible parameter as const/immutable has a cost, and I don't think 
the number of bugs it prevents justifies it.  If it was the default the cost 
wouldn't exist. 



More information about the Digitalmars-d mailing list