[fpc-pascal] Re: classes initialization
L
L at z505.com
Wed Mar 26 00:18:00 CET 2008
I wrote:
>
> I think something like:
>
> procedure test;
> var blah: integer = 0;
> begin
> end;
>
> Is useful.. i.e. initialized variables that are done on the spot.
>
To expand on this.. not only local scope vars, but global..
var
global: integer = 0;
I agree is much clearer than leaving it to the assumption:
// this will be zero.. bad assumption
var
global: integer;
I wrote:
> And similarily a record could be:
>
> procedure test;
> var blah: TRec autoinit;
> begin
> end;
>
This would be a good global habit to get into also for globals:
var
global: Trec autoinit;
or
var
global: Trec;
begin
init(global)
end;
The problem with the above is that sometimes the global is further away
in your code than you eyes can see, hence the inline declaring of
initialization "right while you are at it" is safer for humans.
Relying on global variables being zero is bad, I agree.. and they should
be iniitalized by habit.. too. Especially when one copies global code
into local code does a problem exist, if one made the assumption of the
globals being initialized then (which may have been true, but now that
they are no longer globals... problem time).
More information about the fpc-pascal
mailing list