[fpc-pascal] Syntax changes suggestions

Santiago A. svaa at ciberpiula.net
Mon Jul 16 13:40:53 CEST 2018


I have some suggestions of change to freepascal syntax, just to debate

(All are backward compatible)

- Declaring variables inside blocks, and loop variables
- Autofree pointers
- Try except finally blocks
- Private declarations in implementation

some of them can be found in 
https://www.codeproject.com/Articles/1252167/Delphi-Language-Progression-Suggestions

**declaring variables inside blocks, and loop variables**

var
  Number1,number2:Integer;
  f:textFile;
begin
   <...>
   while not eof(f) do begin
      Readln(f,number1,number2);
      if number1>number2 then
        begin
          var swapnum:Integer;// declaring in a block. Even initializing 
it, var swapnum:Integer:=Number1;
          swapnum:=number1;
          number1:=number2;
          number2:=swapnum;
        end;
   end;
   <...>
end;

---------------

for var i:integer:=1 to 100 do
    begin
       <...>
    end;

---------------

**autofree pointers**

procedure foo;
   var s:TStringList; auto;// you add "auto", like absolute
begin
   s:=TStringList.create;
   <..>
   // s is freed automaticallyat the end of block, without try finally
end;

That combined with declaring inside blocks would make things less 
verbose avoiding a lot of try finally.

**try except finally blocks**

instead of

------------------
  try
     try
       <...>
     except
        <...>
     end;
  finally
     <...>
  end;
------------------

just write

------------------
  try
     <...>
  except
     <...>
  finally
     <...>
  end;

**Private declarations in implementation**

In the implementation, being able to implement a private method without 
declaring it in the interface part.
You just write:

-------------------------
implementation

procedure TMyClass.MyPrivateMethod;
begin
   <...>
end;
-------------------------

And if it is not declared in the interface part, it is assumed as private.
It is a private method, nobody is aware of it outside of the 
implementation, it can't be used in derived classes, it unnecessary in 
the interface, and needn't to be declared.

The same could be applied for private vars. :

--------------------------
implementation

var
  TMyClass.privateVar: Integer;
--------------------------

I suppose this is more difficult with variables than with methods, 
because of reserving memory etc, but it would be handy.

-- 
Saludos

Santiago A.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180716/5cd64c69/attachment.html>


More information about the fpc-pascal mailing list