Recent

Author Topic: Innovation in the language  (Read 7507 times)

AccurateAlx

  • New member
  • *
  • Posts: 7
Innovation in the language
« on: November 20, 2021, 08:08:44 pm »
Hello everyone.
I will not beat around the bush and get straight to the point.
How do you look at the expense of adding a new language construction.

try
except
finally
end;

It is interesting to know how difficult it is to implement it.

I apologize in advance for the Russian accent
« Last Edit: November 20, 2021, 08:15:27 pm by AccurateAlx »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Innovation in the language
« Reply #1 on: November 20, 2021, 08:15:14 pm »
Redundant.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki

AccurateAlx

  • New member
  • *
  • Posts: 7
Re: Innovation in the language
« Reply #3 on: November 20, 2021, 08:41:37 pm »
I have read the thread, thank you.
But is anyone talking about replacing the standard "try except" or "try finally"? We are talking about adding a new construct. The branch says that if inside "try except finally end" object creation doesn't happen, then "finally" will refer to garbage. And if I try to create an object in the "try finally" block and it doesn't create an object, the "finally" will also refer to garbage. If a person is holding a gun, that doesn't mean you have to look at the muzzle and pull the trigger. That's no reason not to add this feature. The language already added all sorts of sugary stuff like templates, generics and soon to be introduced attributes, and such a cool thing is not. It would be nice to read the old thread, but I could not find it.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Innovation in the language
« Reply #4 on: November 21, 2021, 01:47:08 pm »
It's syntactic sugar - because both tryfinallyend and tryexceptend already exist - and it does not add any signifcant benefit. Not to mention that there are use cases where the finally should come before the except and then others where it's the other way round.
TL;DR: There is no interest of the developers to add this.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Innovation in the language
« Reply #5 on: November 21, 2021, 02:08:50 pm »
It's syntactic sugar - because both tryfinallyend and tryexceptend already exist - and it does not add any signifcant benefit. Not to mention that there are use cases where the finally should come before the except and then others where it's the other way round.
TL;DR: There is no interest of the developers to add this.

While agreeing that there's no justification for the change suggested, I'd note that IMO it would be desirable to allow "start" as an alternative to "try" in the try-finally-end syntax (i.e. in the same way that "otherwise" aliases "else" in case statements.

That would make it slightly easier to disentangle things for confused newbies.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

fabiopesaju

  • Jr. Member
  • **
  • Posts: 93
Re: Innovation in the language
« Reply #6 on: November 21, 2021, 05:04:22 pm »
I use this structure a lot...

Code: Pascal  [Select][+][-]
  1. var
  2.   i: integer;
  3. begin
  4.   try
  5.     try
  6.       i := 1 / 0;
  7.     except
  8.       //actions to perform, such as logging errors
  9.     end;
  10.   finally
  11.     //actions to perform, such as releasing variables
  12.   end;
  13. end;  

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Innovation in the language
« Reply #7 on: November 21, 2021, 05:44:07 pm »
I use this structure a lot...

Well /don't/, since you risk a change in the compiler optimising it to a compilation error.

If you want to do something like that use Assert(false...

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

AccurateAlx

  • New member
  • *
  • Posts: 7
Re: Innovation in the language
« Reply #8 on: November 21, 2021, 06:04:31 pm »
I use this structure a lot...

Code: Pascal  [Select][+][-]
  1. var
  2.   i: integer;
  3. begin
  4.   try
  5.     try
  6.       i := 1 / 0;
  7.     except
  8.       //actions to perform, such as logging errors
  9.     end;
  10.   finally
  11.     //actions to perform, such as releasing variables
  12.   end;
  13. end;  

I support you, I myself use this construction very often. I don't understand what this add-on should break in the compiler. Since there is a request to add such a construction, not only from me, then isn't this a reason to think about it, especially since this is not the first discussion. Can someone explain to me what the fundamental difficulty is to add this? Only objectively. There is even such a construction in C #.

AccurateAlx

  • New member
  • *
  • Posts: 7
Re: Innovation in the language
« Reply #9 on: November 21, 2021, 06:12:00 pm »
It's syntactic sugar - because both tryfinallyend and tryexceptend already exist - and it does not add any signifcant benefit. Not to mention that there are use cases where the finally should come before the except and then others where it's the other way round.
TL;DR: There is no interest of the developers to add this.

So what's the problem? If necessary, then use try finally in try except block, this is an extension of the language, not a replacement.

AccurateAlx

  • New member
  • *
  • Posts: 7
Re: Innovation in the language
« Reply #10 on: November 21, 2021, 06:16:07 pm »
There are ways of getting around that of course..
 
 First set the Object to Nil and test it later for a NIL

 also you can use a local variable that is set to false first and at the end of the TRY section before it enters the Finally section you can set it to true and then test that condition in the finally section.

etc

 there are always ways.

I don't quite understand you. I gave an example from another thread. They wrote that the innovation would not work well and argued this by referring to "garbage"

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Innovation in the language
« Reply #11 on: November 21, 2021, 06:27:31 pm »
We have it already, but the actual keywords are "try try" and "end finally":

Code: Pascal  [Select][+][-]
  1.   try try
  2.  
  3.   except
  4.  
  5.   end finally
  6.  
  7.   end;
  8.  

Soner

  • Sr. Member
  • ****
  • Posts: 305
Re: Innovation in the language
« Reply #12 on: November 21, 2021, 06:34:51 pm »
I use this structure a lot...

Code: Pascal  [Select][+][-]
  1. var
  2.   i: integer;
  3. begin
  4.   try
  5.     try
  6.       i := 1 / 0;
  7.     except
  8.       //actions to perform, such as logging errors
  9.     end;
  10.   finally
  11.     //actions to perform, such as releasing variables
  12.   end;
  13. end;  
The outer try-finally-end is not needed, because you catch all exceptions in except-section and the program runs normally after except-section.

dseligo

  • Hero Member
  • *****
  • Posts: 1196
Re: Innovation in the language
« Reply #13 on: November 21, 2021, 06:50:02 pm »
The outer try-finally-end is not needed, because you catch all exceptions in except-section and the program runs normally after except-section.

And if he have Exit like below?

Code: Pascal  [Select][+][-]
  1. var
  2.   i: integer;
  3. begin
  4.   try
  5.     try
  6.       i := 1 / 0;
  7.       Exit;
  8.     except
  9.       //actions to perform, such as logging errors
  10.       Exit;
  11.     end;
  12.   finally
  13.     //actions to perform, such as releasing variables
  14.   end;
  15. end;  

dseligo

  • Hero Member
  • *****
  • Posts: 1196
Re: Innovation in the language
« Reply #14 on: November 21, 2021, 06:53:06 pm »
I use this structure a lot...

Well /don't/, since you risk a change in the compiler optimising it to a compilation error.

If you want to do something like that use Assert(false...

MarkMLl

Do you mean line 'i := 1 / 0;' or something else? I think he used this just as an example.

 

TinyPortal © 2005-2018