[fpc-pascal] Fwd: What to do to get new users
Nikolay Nikolov
nickysn at gmail.com
Fri Jan 24 02:38:25 CET 2025
On 1/24/25 3:21 AM, Hairy Pixels via fpc-pascal wrote:
> On Jan 24, 2025 at 2:10:53 AM, Santi via fpc-pascal
> <fpc-pascal at lists.freepascal.org> wrote:
>> procedure foo()
>> var
>> s1: TStringList;
>> s2: TStringList;
>> s3: TStringList;
>> begin
>> s1:=TStringList.create;
>> try
>> s2:=TStringList.create;
>> try
>> s3:=TStringList.create;
>> try
>> doWhatever(s1,s2,s3)
>> finally
>> s3.free;
>> end;
>> finally
>> s2.free;
>> end;
>> finally
>> s1.free;
>> end
>> end;
>
> Honestly this is the worst memory management strategy I've seen in any
> language. It's more keywords than code! It was Delphi’s idea right? If
> you’re making some UI app in 2025 a garbage collector or full ARC is
> perfectly fine so I don’t see how they get away with selling this.
Maybe because there's a much better way to write it:
procedure foo();
var
s1: TStringList = nil;
s2: TStringList = nil;
s3: TStringList = nil;
begin
try
s1:=TStringList.create;
s2:=TStringList.create;
s3:=TStringList.create;
doWhatever(s1,s2,s3);
finally
FreeAndNil(s3);
FreeAndNil(s2);
FreeAndNil(s1);
end;
end;
Best regards,
Nikolay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20250124/5d24f1d2/attachment-0001.htm>
More information about the fpc-pascal
mailing list