Revert attributes to their defaults with default keywords

aldanor via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 9 06:26:25 PST 2015


On Friday, 9 January 2015 at 13:01:14 UTC, Steven Schveighoffer 
wrote:
> On 1/9/15 7:47 AM, Daniel Kozák via Digitalmars-d wrote:
>> V Fri, 09 Jan 2015 07:21:02 -0500
>> Steven Schveighoffer via Digitalmars-d 
>> <digitalmars-d at puremagic.com>
>> napsáno:
>>
>>> On 1/9/15 6:57 AM, Daniel Kozak wrote:
>>>> I often have code like this:
>>>>
>>>> class A {
>>>>      final:
>>>>      nothrow:
>>>>      ...
>>>>      some methods
>>>>      ...
>>>> }
>>>>
>>>> Problem comes when I need add methods which for eg.: throws 
>>>> or need
>>>> to be virtual.
>>>>
>>>> I can put them before final: but this is not perfect, 
>>>> because I
>>>> prefer when methods are place in specific order (method abc 
>>>> call
>>>> method asd so asd is bellow abc and so on).
>>>>
>>>> So today I download dmd source and make some small 
>>>> modification
>>>> (only few lines) and this is the result:
>>>>
>>>> http://dpaste.dzfl.pl/472afc938397
>>>
>>> Nice, but I don't like the fact that it bluntly returns all
>>> attributes to default.
>>>
>>> For example, if you need to remove the final attribute, but 
>>> not
>>> nothrow, I'm assuming it looks something like:
>>>
>>> default nothrow void foo()
>>>
>>> which doesn't read very well.
>>>
>>> If we are going to do this, I'd rather see something like has 
>>> been
>>> suggested before -- parameterizing attributes:
>>>
>>> final(false) -> remove final
>>>
>>> This allows compile-time booleans to modify attributes in 
>>> ways that
>>> are extremely difficult in templates today.
>>>
>>
>> I think both ways shoud be available
>>
>> when I need remove just one attr than attr!false is nice but 
>> when I
>> need remove for eg: 3 or more it will look like:
>>
>> void someFunc final(false) pure(false) nothrow(false)
>>
>> in this case I think that:
>>
>> default void foo() nothrow looks OK now :)
>>
>
> I'd rather combine the parameterization with attribute sets 
> (i.e. aliasing sets of attributes to one symbol). The 'default' 
> idea is ok, but I think it's too clever -- the word "default" 
> doesn't immediately say "attributes", so it's going to confuse 
> people.
>
> -Steve

It could work both ways at the same time.

Maybe even something like "default(pred) final(pred) nothrow" --> 
if pred is compile-time-true, reset all attributes and then add 
final/nothrow; if it's compile-time-false, disable final and 
enable nothrow.


More information about the Digitalmars-d mailing list