[fpc-pascal] Re: operator overloading and counting references / creating / destoying anonymous instances

Flávio Etrusco flavio.etrusco at gmail.com
Fri Jul 29 23:16:52 CEST 2011


On Fri, Jul 29, 2011 at 7:31 AM, Henry Vermaak <henry.vermaak at gmail.com> wrote:
> On 29/07/11 06:39, Jürgen Hestermann wrote:
>>
>>
>> Bernd schrieb:
>>  > Occasionally I hear other people mentioning operator overloading as a
>>  > must-have feature of any decent language but I wonder what real-world
>>  > problems they are actually solving with it.
>>
>> I think operator overloading is a pain. As you said: What is the
>> advantage? For me operators should be defined by the language only
>
> It improves readability, making it more logical.  Say for instance you are
> working on Galois fields and you have to do arithmetic on the elements like
> this:
>
> g1 + g2 / g3
>
> If you don't have operator overloading, you have to do it with functions,
> like this:
>
> gf_add(g1, gf_div(g2, g3))
>
> This is not very readable, I'm sure you will agree.  They have to be used
> carefully, however.

That's the problem, you always have to be very careful.
They are easy to overlook in the code.
You can circumvent type-checking.
One more thing for the IDE to support (if it doesn't, you're royally screwed).
At least in *Pascal strings are native types, so one less problem (and
a big one in C++) to worry.

>> clear. But now there is no way back. It's implemented. Pascal moves in C
>> direction...
>
> Troll.  C has no operator overloading.
>
> Henry

Of course he meant C++.

-Flávio



More information about the fpc-pascal mailing list