Henry Vermaak schrieb:
>> 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.
Just the opposite! It hides important imformation for the reading person.


> 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. No, I don't agree at all. The procedure call clearly shows me that a complex calculation is done instead of an (atomic) add and division command on numbers.

For me the basic operators should be just that: Basic operators. Otherwise you have problems to interpret code.

For example, IMO the assignment := should just copy bytes, nothing more. There can be additional range checks but it should not lead to side effects you are not aware of. I had a hard time to find out that a simple "A:=nil" on a dynamic array does more than just copying bytes to the memory adress of A. As a side effect it uses the current pointer in A and frees memory. But I had just read this data from a file so that the pointer was garbage. I just wanted to init A. But what a surprise that this atomic assignment command does more on dynamic arrays! If I create pointers to types on my own, this does not happen.

Operator overloading weakens the meaning of the operators. It can be just everything but you do not see it anymore.


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

I meant it in a more general spirit: Pascal was created to be clear and unambiguous while C was an improved assembler which ignored any kind of readability. Now all these obscure things creep into Pascal too so that in this respect there is not much difference between current C(++) and current Pascal compilers anymore.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to