Re: [fpc-pascal] Traits Proposal

2021-02-18 Thread Sven Barth via fpc-pascal
Am 18.02.2021 um 23:58 schrieb Ryan Joseph via fpc-pascal: On Feb 18, 2021, at 3:07 PM, Sven Barth wrote: So "class type method resolution" is what's missing? I never used the interface method resolution so I don't really understand this feature. What needs to happen as far as the compiler

Re: [fpc-pascal] Traits Proposal

2021-02-18 Thread Martin Frb via fpc-pascal
On 18/02/2021 23:47, Ryan Joseph via fpc-pascal wrote: On Feb 18, 2021, at 12:33 PM, Martin Frb via fpc-pascal wrote: TMyFoo = class(specialize TTrait) procedure Foo; end; Of course that can get out of hand, if you want to include many traits. I'm not really understand this at

Re: [fpc-pascal] Traits Proposal

2021-02-18 Thread Ryan Joseph via fpc-pascal
> On Feb 18, 2021, at 3:07 PM, Sven Barth wrote: > >> So "class type method resolution" is what's missing? I never used the >> interface method resolution so I don't really understand this feature. What >> needs to happen as far as the compiler is concerned? > > The problem is this: if you h

Re: [fpc-pascal] Traits Proposal

2021-02-18 Thread Ryan Joseph via fpc-pascal
> On Feb 18, 2021, at 12:33 PM, Martin Frb via fpc-pascal > wrote: > > TMyFoo = class(specialize TTrait) > procedure Foo; > end; > > Of course that can get out of hand, if you want to include many traits. I'm not really understand this at all. You're still using subclassing, which i

Re: [fpc-pascal] Traits Proposal

2021-02-18 Thread Martin Frb via fpc-pascal
On 18/02/2021 22:42, Sven Barth wrote: You need to constrain T as a TObject, then it works. Ah that works. With 2 restrictions TBase can be any class, since a trait can be applied to any class. So the only known common base is TObject. (restriction 1) But "TBase: TObject" means that the trai

Re: [fpc-pascal] Traits Proposal

2021-02-18 Thread Sven Barth via fpc-pascal
Am 17.02.2021 um 16:22 schrieb Ryan Joseph via fpc-pascal: On Feb 17, 2021, at 6:10 AM, Sven Barth wrote: Simply because no one has come around to implement it yet. The class type case is more complicated than the interface case. (Same would be true for record and objects) So, yes, we'll ne

Re: [fpc-pascal] interfaces and smartpointers [was Traits Proposal]

2021-02-18 Thread Sven Barth via fpc-pascal
Am 18.02.2021 um 02:25 schrieb Ryan Joseph via fpc-pascal: On Feb 17, 2021, at 4:51 PM, Benito van der Zander via fpc-pascal wrote: I benchmarked it years ago, I do not remember the details. But InitInterfacePointers was bad. Just look at it: That's not great for sure. Fillchar could be a

Re: [fpc-pascal] Traits Proposal

2021-02-18 Thread Sven Barth via fpc-pascal
Am 18.02.2021 um 20:33 schrieb Martin Frb via fpc-pascal: could be written as   generic TTrait = class(T)     procedure Bar;   end;   TMyFoo = class(specialize TTrait) procedure Foo;   end; Of course that can get out of hand, if you want to include many traits. You need to constrain T a

Re: [fpc-pascal] Traits Proposal

2021-02-18 Thread Martin Frb via fpc-pascal
On 18/02/2021 18:46, Ryan Joseph via fpc-pascal wrote: On Feb 18, 2021, at 10:40 AM, Benito van der Zander via fpc-pascal wrote: Traits are like reverse type helpers. With the type helper you first declare the class and then the extending helper. Indeed, but with the crucial distinction th

Re: [fpc-pascal] Traits Proposal

2021-02-18 Thread Ryan Joseph via fpc-pascal
> On Feb 18, 2021, at 10:40 AM, Benito van der Zander via fpc-pascal > wrote: > > Traits are like reverse type helpers. With the type helper you first declare > the class and then the extending helper. Indeed, but with the crucial distinction that helpers don't allow fields, only methods.

Re: [fpc-pascal] Traits Proposal

2021-02-18 Thread Benito van der Zander via fpc-pascal
Hi, The problem is that, we like OOP inheritance but when we extend classes we are forced into a single hierarchy. there is another way to extend classes without inheritance: type helpers Traits are like reverse type helpers. With the type helper you first declare the class and then the ext