[fpc-devel] FPC implementation of attributes for language parts.

Sven Barth pascaldragon at googlemail.com
Wed Apr 13 14:34:28 CEST 2016


Am 13.04.2016 13:02 schrieb "Michael Van Canneyt" <michael at freepascal.org>:
>
>
>
> On Wed, 13 Apr 2016, Maciej Izak wrote:
>
>> Moved from: "Initialize/Finalize management operators and Default
>> intrinsic". I'd like to keep Initialize/Finalize topic more clear ;P
>>
>> Small introduction:
>>
>> for selected language elements in Delphi is possible to use attributes.
For
>> example in Delphi we have:
>>
>>  TCustomAttribute = class(TObject)
>>  end;
>>  WeakAttribute = class(TCustomAttribute);
>>  UnsafeAttribute = class(TCustomAttribute);
>>  RefAttribute = class(TCustomAttribute);
>>  VolatileAttribute = class(TCustomAttribute);
>>
>> which is used like this:
>>
>> procedure Foo([ref] const X: TFoo); // AFAIK FPC equivalent is procedure
>> Foo(constref X: TFoo);
>>
>> or like this for TObject field for ref. count for ARC:
>>
>> [Volatile] FRefCount: Integer;
>
>
> Sorry. This is simply very bad design.
>
> 1. We already have a syntax for this kind of thing, it is called
modifiers.
>    No need to introduce a second syntax. You just introduce extra
modifiers.
>
> 2. You make the COMPILER dependent on USER-DEFINED classes.
>    What kind of nonsense is that ?
>    It is even worse than the enumerator syntax Borland/Embarcadero
invented.
>
> If the compiler needs to know about it and act on it (and it does for
ARC), then it must be a keyword or modifier.
>
> Attributes are meant for user-space information.
>
> The compiler has no business with it, from the point of view of the
compiler
> the presence or non-presence of attributes is entirely irrelevant. It is
> meant to be extracted easily by the user. No more, no less.
>
> Attributes used like this are self-contained. You can use it or not, it
> makes no difference to the compiler. This is an example of _good_ design.
>
> If you use attributes to start controlling ARC or whatever other
_language feature_, this is _bad_ design, because you link one feature to
another, which simply is not related to it at all.

Agreed. Attributes are nice and well, but only for the area they had been
designed for.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160413/32cb085b/attachment.html>


More information about the fpc-devel mailing list