[fpc-pascal] Writeable typed constants - what's the point?

Martin Friebe fpc at mfriebe.de
Thu Jun 18 13:32:02 CEST 2009

Graeme Geldenhuys wrote:
> Martin Friebe wrote:
>> And if I understand the changes where mad, because this "feature" was
>> broken before:
> To quote myself, even though I know one shouldn't. ;-)
>  "I know they were introduced for the better."
> I was not arguing the point that those changes should not have been
> made. I was simply stating that other projects code was broken due to
> behaviour changes made in FPC. This was my counter argument to Vincent's
> reply that it would break existing code.
I know you said that, but I tried to highlight something that imho is 
missing in this statement.

The change with "properties as var param" only broke existing code, if 
this existing code was already broken. The compiler just compiled the 
broken code before. Nor the compiler rejects the broken code.

To explain:
- A property has always been defined as beeing equal in treatment to the 
result of a function. This is the purpose of a property. If you do not 
want to be able to replace the property getter/setter by a 
function/procedure => you can just publish the variable.
- a function result was never allowed as "var param" (just not possible)
=> In other words being allowed to do the impossible (defeating the 
purpose of a property), means being allowed to compile broken code => 
which must be fixed, even if it breaks projects that relied on it. But 
those projects should anyway never have compiled.

procedure a;
 i: integer = 1;

is a documented, working feature, there is nothing broken about it.

Anyway here another view on the topic:

1) I think the feature in itself is useful and should exist
2) the current syntax of the feature is not very self-explaining. 
Reading code with this feature is misleading

If at all something should be done about, imho it was introducing an 
alternative, more readable syntax, but keeping the old (because it is a 
documented feature / maybe add a compiler hint for the old syntax)

People who care about the read ability of their code could the write a 
more intuitive form.


procedure a;
  x: integer = 1; static;

or if there is, or is planned, whatever syntax there is or will be for 
class members of this kind

Best Regards

More information about the fpc-pascal mailing list