const, final, scope function parameters

Johan Granberg lijat.meREM at OVEgmail.com
Sun May 27 02:50:19 PDT 2007


Rioshin an'Harthen wrote:

> 
> "janderson" <askme at me.com> kirjoitti viestissä
> news:f3bijn$t1h$1 at digitalmars.com...
>> Walter Bright wrote:
>> [snip]
>>> 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.
>>
>> On this point, couldn't it be something like, if you define const, final
>> or scope then the default "const final scope" is removed?
>>
>> [snip]
> 
> I find myself thinking that this might be a better way.
> 
> So something akin to this (for in-only parameters)
> 
> void foo(int bar) - bar is const final scope
> void foo(in int bar) - bar is normal
> void foo(const int bar) - bar is const
> void foo(final int bar) - bar is final
> void foo(scope int bar) - bar is scope
> etc. with the combinations
> 
> Any specifier of {in|const|final|scope} cancels the const final scope
> default of the parameter; mixing "in" with "const", "final" or "scope" is
> no problem, since the only use for "in" is to cancel the default of
> const final scope, while any of those three cancels the default and
> toggles itself on.
> 
> (Basically, in and no specifier swap places compared to Walter's
> suggestion.)

I like this one, basically it's safe by default and saves typing in the most
common case, it would also avoid the problem I see in c++ sometimes, that
people don't write const because it's more typing. Walter please
reconsider, const by default will be worth any initial hassle.



More information about the Digitalmars-d mailing list