const, final, scope function parameters

Regan Heath regan at netmail.co.nz
Sun May 27 08:31:59 PDT 2007


Walter Bright Wrote:
> It looks like making "const final scope" be the default for function 
> parameters is going to be infeasible. The troubles are that:
> 
> 1) It seems to knock a lot of people for a loop, who will be assuming 
> that an undecorated name would be like an undecorated name for a local 
> or global variable.

So why not make globals 'const scope final' also.  'scope' in this case being the global program scope.  Many globals are initialised and then simply read from, the rest would be marked 'mutable' and would then indicate a variable that could change and in the case of multithreaded apps clearly indicate a variable which needed locking/protection. 

> 2) Having to turn off one of the const, final, or scope, introduces the 
> need for some sort of "not" keyword, like mutable, !const, !final, etc. 
> It comes off looking bizarre.

Using 'mutable' where you want a mutable parameter/global doesn't look bizarre to me.  Do you have a specific example in mind where it looks bizarre.

> However, making "in" be equivalent to "const final scope" does seem to 
> work fine, requires no new keywords, and doesn't seem to confuse anyone.

Who are you testing it on?  Are they a) long time D users or b) new users to D, perhaps long time C++ users?  c) some other group?

> On a related note, "cstring" has received universal condemnation <g>, so 
>    I'll just have to make "string" work.

Excellent.

Regan Heath



More information about the Digitalmars-d mailing list