[fpc-pascal] Traits Proposal

Ryan Joseph genericptr at gmail.com
Wed Feb 10 16:59:07 CET 2021



> On Feb 10, 2021, at 8:41 AM, Michael Van Canneyt <michael at freepascal.org> wrote:
> 
> I heavily object to this; We have way too much keywords as it is already. So unless there really is no other way I don't think we should introduce
> even more.

I guess the first question is whether a "trait" is a new construct or just a way to import fields/methods from a  class. I like the idea of a formal new type so we can limit the scope of the feature instead of taking on the baggage of an old type like "object". I'll wait to hear from the compiler team however.

Looking back at the old thread Sven said:

"What I'm still missing however is a real use case. What you have 
presented as an example can just as easily be done with the existing 
delegates. And just to avoid having to cast the instance to the 
interface is in my opinion not enough reason for a new feature. "

so the idea wasn't rejected outright but I'm not sure if this idea even had their consent. I think traits/mixins are the way of the future for OOP but that's not certain for FPC yet. For example C# is a major language which is still single-inheritance only.

btw, here are some links I've gathered on how other languages support this concept:

• PHP (trait): https://www.php.net/manual/en/language.oop5.traits.php
• Python (mixin): https://devtut.github.io/python/mixins.html#mixin
• Swift (default protocol):
	• https://nshipster.com/swift-default-protocol-implementations/http://machinethink.net/blog/mixins-and-traits-in-swift-2.0/

Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list