Recent

Author Topic: Defer Mechanism for FreePascal  (Read 3663 times)

Sniper

  • New Member
  • *
  • Posts: 36
Defer Mechanism for FreePascal
« on: June 26, 2021, 12:16:28 pm »
Everybody who writes in Golang know about it's defer mechanism.

I found proposal of this useful thing for C (C2x)

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2542.pdf

Do FPC core developers are interested in "defer" mechanism in freepascal?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9522
  • FPC developer.
Re: Defer Mechanism for FreePascal
« Reply #1 on: June 26, 2021, 01:31:17 pm »
Sound like procedural form of exception handling. We already have such things in try.except and try.finally.

Bi0T1N

  • Jr. Member
  • **
  • Posts: 65
Re: Defer Mechanism for FreePascal
« Reply #2 on: June 26, 2021, 01:49:16 pm »
Sound like procedural form of exception handling. We already have such things in try.except and try.finally.
I think that was also the outcome of the thread on the mailing list.

PascalDragon

  • Hero Member
  • *****
  • Posts: 3317
  • Compiler Developer
Re: Defer Mechanism for FreePascal
« Reply #3 on: June 27, 2021, 01:11:53 pm »
Sound like procedural form of exception handling. We already have such things in try.except and try.finally.
I think that was also the outcome of the thread on the mailing list.

Correct. There is no need for a defer. A tryfinally might be more verbose, but why sugar coat it?
Also e.g. Lazarus helps you out there quite a bit by completing a try to a tryfinally, a tryf to a tryfinally with the cursor in the finally-block and a trye to a tryexcept. And then there's the nifty trycf which will create the following code:

Code: Pascal  [Select][+][-]
  1. VarName := TMyClassName.Create;
  2. try
  3.              
  4. finally
  5.   VarName.Free;
  6. end;

Where the IDE highlights VarName and TMyClassName as editable blocks you can switch between with Tab (and editing VarName will edit both locations).

Alextp

  • Hero Member
  • *****
  • Posts: 1373
    • UVviewsoft
Re: Defer Mechanism for FreePascal
« Reply #4 on: June 27, 2021, 01:29:35 pm »
@PascalDragon,
thanks for pointing that out. Offtopic: I am your fan, trying to read all your last messages. :)

 

TinyPortal © 2005-2018