[fpc-pascal] Traits Proposal

Martin Frb lazarus at mfriebe.de
Thu Feb 11 05:14:19 CET 2021


On 11/02/2021 04:13, Ryan Joseph via fpc-pascal wrote:
>
>> On Feb 10, 2021, at 7:47 PM, Martin Frb via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>>
>> In that case IIRC, it was said traits are not allowed constructors. Why?
> Traits are meant to be a way to import fields/methods and is based off of "object" (so it's on the stack). This is also important for using properties to alias the imported fields. It's the same with subclassing, you don't need to manually allocate the super class because it's all one structure with a shared memory space. The idea is to make a viable alternative to inheritance in the simplest way possible.
"don't need to manually allocate"
I know, I am using old "object" for that already. So that is not new 
when traits come.

Hence I concluded, the "trait" feature is exactly and only an automated 
generation of forwarder-methods (well exactly they are no longer 
forwarders, but imported / to the user that writes a call to them that 
is the same in the end)

But if the above conclusion is correct (no more, no less that replacing 
the need for forwarders ), then it is reasonable to want the same 
concept for other types... I do not actually advocate it. I simple point 
out what would logically follow (rather than what may or may not be good)




More information about the fpc-pascal mailing list