[fpc-devel] Proposal: Enhanced replacement for assignment operators

Martin fpc at mfriebe.de
Sat Aug 7 17:17:45 CEST 2010


  On 07/08/2010 16:03, Hans-Peter Diettrich wrote:
> Marc Weustink schrieb:
>
>>>> What is wrong with :
>>>>
>>>> MyObj.PointArrayField[i] := MyObj.PointArrayField[i] +
>>>>   FunctionReturningPointOffset(param)
>>>
>>> The need for duplicating a long expression, with chances for typos :-(
>>
>> Choose shorter expressions and/or use ctrl+space
>
> And how do I find out, whether two expressions are the same, while 
> *reading* the code?

Lazarus can highlight occurrences of equal text => select one as block, 
the other one will be highlighted....
Of course, that is beside the point, totally missing your argument (so 
save yourself from pointing out the deficiencies of the above statement).

But honestly, no matter if you use += or the above form, it is hard to 
read.

The data in MyObj.PointArrayField belongs to MyObj => so why not tell 
MyObj what to do with that data?

MyObj.AddOffsetToField(i, FunctionReturningPointOffset(param));

Or make fields them self objects (or a record-with-methods /fpc "type 
foo=object end"):
MyObj.Field[i].AddOffset( FunctionReturningPointOffset(param));

Oh, yes, it's another 3 or 4 line method... so what?  (as for speed, 
inline it).
There are many usages for subroutines, not only the ability to call the 
same code from more than one location. Using a subroutine to extract and 
name a piece of code for better readabilit *can* be perfectly valid and 
desirable.

Martin




More information about the fpc-devel mailing list