const, final, scope function parameters
Bill Baxter
dnewsgroup at billbaxter.com
Wed May 30 11:51:42 PDT 2007
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
More information about the Digitalmars-d
mailing list