[fpc-devel] Postfix operator overload or default properties
pascaldragon at googlemail.com
Fri Jun 7 23:08:03 CEST 2019
Am 07.06.2019 um 23:06 schrieb Ryan Joseph:
>> On Jun 7, 2019, at 4:56 PM, Sven Barth via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
>> Because I don't want to open the can of worms that is going to be overloading the postfix "operator". People are going to abuse the hell out of it (they will with default properties as well, don't get me wrong there), making the language much harder to read. Nowadays you can rely on the "." denoting some sub element. With operator overload using a "." could mean triggering some credit card payment (I'm exaggerating here, but this would technically be possible).
> The default properties are a much bigger can of worms. That’s why I suggested the operator overload.
> With default properties you can do this:
> rec: TMyRecord<TObject>; // assume TMyRecord has a default property to a field with TObject
> // assignment operator overloads
> rec := TObject.Create;
> // classref access
> // all statements, with, while, if, for etc...
> with rec do
> while rec do
> // postfix, fields and function overloads
> // all binary AND unary overloads
> if rec = nil then
> All the postfix operator allows is “.” access. That’s like 90% less intrusion into the compiler. Much smaller can of worms. Sorry C++ had the smarter idea here. Limit the access to “.” and if the user wants assignments or equality etc… they overload other operators. Please tell me how that’s a bigger can of worms.
Before we add a postfix operator I prefer not to add *any* of this *at all*.
More information about the fpc-devel