Joao Morais replied to Jonas with:

>I think I didn't get your point. What about this piece of code:
>
>interface
>
>function foo: tfoo;
>
>implementation
>
>var
> _foo: tfoo;
>
>function foo: tfoo;
>begin
> if not assigned(_foo) then
>   _foo := tfoo.create;
> result := _foo;
>end;
>
>Is it safe?

What about this:

var
 _foo: tfoo = nil;

That way you declare it right there and then.. ensuring it is not assigned.

Hence why I think a good human practice is to always init everything even if it psychologically affects some people in ways such as "will this slow the program down though? Do I need to init this stuff if I am going to init some of it later"? which is evil premature optimization that causes bugs.

L505

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to