[fpc-devel] class operator overloads

Ryan Joseph ryan at thealchemistguild.com
Sun Apr 21 21:03:32 CEST 2019



> On Apr 20, 2019, at 9:56 AM, Ryan Joseph <ryan at thealchemistguild.com> wrote:
> 
>> On Apr 16, 2019, at 8:43 PM, Ryan Joseph <ryan at thealchemistguild.com> wrote:
>> 
>> I see why that could be a problem but aren’t users reasonable for not doing dangerous things in a language like Pascal with low-level memory access? They can already do this anyways via operator functions so it’s already too late. :) If you want a language that prioritizes safety then Pascal is already a bad choice so I think most people know how to be safe.
> 

I just noticed this didn’t get posted (as happens often for some reason) so I’m resending. Sorry for the noise if it gets posted twice.

====================================

I had some time today so I investigated what it would take to add class operators and it’s actually totally trivial.

Given that there are some compromises we could possibly make.

1) Allow class operators but put them behind a mode switch so the user explicitly knows they’re opting in. Users can already add operators to classes via operator functions so this just formalizes the feature and syntax which was introduced for records.
2) Only use a subset of class operators that return booleans (i.e. comparison, in) so there isn’t a potential for allocating temporary memory. Better than nothing but I’d prefer users who understand operator overloads be allowed full access.

Does that sound reasonable?

Regards,
	Ryan Joseph




More information about the fpc-devel mailing list