const, final, scope function parameters

Bruno Medeiros brunodomedeiros+spam at com.gmail
Fri Jun 1 14:22:52 PDT 2007


Bill Baxter wrote:
> Bruno Medeiros wrote:
>> 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.
>>>
>>> 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.
>>>
>>> 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.
>>>
>>> On a related note, "cstring" has received universal condemnation <g>, 
>>> so   I'll just have to make "string" work.
>>
>> I'm gonna repost my question in this thread:
>>
>> What is the reasoning behind the idea of 'scope' being the default 
>> together with 'const' and 'final'? I understand (and agree) why 
>> 'final' and 'const' should be the default type modifiers for function 
>> parameters, but why 'scope' as well? Does it look like 'scope' would 
>> be more common than non-scope?
> 
> Do a majority of the parameters you pass to functions get stored 
> somewhere that will last beyond the scope of the function?  From what I 
> understand scope on a parameter will not mean that class objects get 
> passed on the stack, if that's what you're thinking.  They'll still be 
> reference parameters, just it will be an error for the function to store 
> that reference in a global or a local static variable.
> 
> So I guess that means most setter methods that take objects will have to 
> declare away the scope part (or in Walter's current way be 'const' 
> rather than 'in'), because storing a reference is their whole reason for 
> being.
> 
> --bb

Hum, in my experience, I wouldn't say the majority of them get stored 
somewhere, but I wouldn't say the majority of them *don't* get stored 
either. I guess both cases are more or less equal (unlike const&final 
which are the majority), even if perhaps the scope case is slightly more 
common. However, being that both cases are similar occurrences, I would 
say that the default case should be same as not having a keyword. (i.e., 
the default case should be the same as not having scope). But this is 
very early opinion, I'm nowhere near sure.

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list