Re: [fpc-pascal] reference-counted function results not initialized to nil

2016-06-28 Thread David Emerson
Philosophical arguments aside, I filed a bug against the documentation, 
since one thing is clear-- that I and others were previously misled into 
believing something that is not true.


http://mantis.freepascal.org/view.php?id=30321

In the report, I included several references where the documentation 
could be improved to make the compiler's behavior more clear. If anyone 
wants to expand on that list, please feel free :)


Also perhaps the wiki could use some work in this regard.

~David.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] which "managed" result types require extra work?

2016-06-28 Thread Michael Van Canneyt



On Tue, 28 Jun 2016, Jürgen Hestermann wrote:


Am 2016-06-28 um 01:13 schrieb David Emerson:
The source of my confusion -- and I suspect that of many others -- is that 
I always assumed a function result was treated like a local variable within 
the function, rather than a parameter to the function.
Since managed types are automatically initialized when they are local 

variables, I assumed a function result was the same.
Unfortunately, the documentation does not make this sufficiently clear in 

describing managed types. I guess I should file a documentation bug.

Exactly my opinion too.
Especially, because it behaved differently with Free Pascal versions prior to 
3!


And it does not behave like a function parameter, it behaves like a *var* 
parameter.

All other types of parameters behave differently!
And while a var parameter can *only* be assigned to a variable (so that it is 
clear

that an existing variable is used) a function result can also be used in an
expression which makes it silently mutate into a global variable! What a 
mess!


And for local variables I can easily set a default value in the declaration 
but not for the function result.

I have to remind me not to forget this in the code.


This has been so since day 1 in Pascal.

Any behaviour other than that was entirely coincidental.

Michae.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] which "managed" result types require extra work?

2016-06-28 Thread Jürgen Hestermann

Am 2016-06-28 um 01:13 schrieb David Emerson:
> The source of my confusion -- and I suspect that of many others -- is that I 
always assumed a function result was treated like a local variable within the 
function, rather than a parameter to the function.
> Since managed types are automatically initialized when they are local 
variables, I assumed a function result was the same.
> Unfortunately, the documentation does not make this sufficiently clear in 
describing managed types. I guess I should file a documentation bug.

Exactly my opinion too.
Especially, because it behaved differently with Free Pascal versions prior to 3!

And it does not behave like a function parameter, it behaves like a *var* 
parameter.
All other types of parameters behave differently!
And while a var parameter can *only* be assigned to a variable (so that it is 
clear
that an existing variable is used) a function result can also be used in an
expression which makes it silently mutate into a global variable! What a mess!

And for local variables I can easily set a default value in the declaration but 
not for the function result.
I have to remind me not to forget this in the code.

It is so logical that managed types are managed (therefore the wording!).
That a function result can inherit old values from prior calls is just the same 
as for
local constants of TP.  But in TP it was at least documented and it was 
predictable.
Now everybody ostracizes such behaviour but instead intruduces the same
for function results.

I used this behaviour of managed types over many years.
Now we all (most of us) had to find out the change the hard way (by debugging).
Many may not even have found this yet because their functions with managed type 
results are used seldomly.
That's quite ignorant C style (where you also have nothing to rely on but need 
to check every compiler (version)).
So yes, "modern" Pascal is no longer the "old" Pascal, but has it become 
better? Meanwhile I doubt this.

And what about perfomance? In most of the cases I am now initializing
what is already initialized. Very strange.


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal