[fpc-pascal] Syntax changes suggestions

Ryan Joseph ryan at thealchemistguild.com
Fri Jul 27 05:19:16 CEST 2018



> On Jul 25, 2018, at 8:05 AM, R0b0t1 <r030t1 at gmail.com> wrote:
> 
> This looks ugly. It also introduces modifiers to variable
> declarations. Some features should not be part of the language, they
> should be built on top of it.


Yeah, introducing modifiers to variables is not so great. You could avoid introducing modifiers but using a new section like “scopevar” which is similar to “threadvar” I guess.

scopevar
  c: TMyClass;
begin
  c := TMyClass.Create;

I accomplish this in my code using an auto release pool which empties at the end of every event loop.

var
  c: TMyClass;
begin
  c := TMyClass.Create;
  c.AutoRelease;

// or
  c := TMyClass.Instance; // calls Create + AutoRelease in the constructor

That’s not so pretty either, involves extra constructors sometimes (if you want to keep things pretty) and it requires extra infrastructure you need to setup. Jonas told me once this is actually more efficient though since it frees multiple objects all at the same time so it decreases heap fragmentation (I think he meant). This idea is heavily utilized in all of Apple’s Cocoa frameworks so it’s a sound solution.


Meh, no free lunch, just food for thought. :)

Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list