Lazarus

Free Pascal => Beginners => Topic started by: yinhuajian on May 30, 2025, 05:49:35 am

Title: About Inline Variable
Post by: yinhuajian on May 30, 2025, 05:49:35 am
Does FreePascal support inline variable declaration like Delphi 12? For example:
var Msg: String := 'Inline variable works!';

If not currently supported, is there any plan to implement this feature? Thank you.
Title: Re: About Inline Variable
Post by: Fibonacci on May 30, 2025, 06:30:23 am
Currently not supported.

As for whether this will ever be implemented, a discussion from last year left me convinced that it probably never will be. It can be implemented, not a problem. User @Warfley even demonstrated that its not that complicated, he managed to partially implement it in a single day. It wasnt a complete implementation though, a bit buggy, but with some more time and effort, it could definitely be made stable and fully functional.

However, Im convinced that even if someone submitted a patch and a merge request for inline vars, it wouldnt be accepted, just like many other improvements have been rejected in the past, such as record composition (something that even Delphi doesnt have, AFAIK).

 >:D Conspiracy theory >:D
Embarcadero pays FPC devs to keep FPC somewhat crippled. If FPC were fully on par with Delphi, there would be little reason to pay for Delphi. If I were Embarcadero, thats what I would do.
Title: Re: About Inline Variable
Post by: Thaddy on May 30, 2025, 07:59:06 am
The reason is simple: inline vars violate the Pascal paradigm of strict separation of declaration and implementation.
Title: Re: About Inline Variable
Post by: vercetti on May 30, 2025, 08:39:21 am
Strange. It would make sense to enable inline variables in {$Mode Delphi}. After all, this mode was introduced to maintain compatibility with Delphi’s syntax and features. Nowadays, inline variables are a standard part of Delphi. I’ve already encountered projects and components using this syntax, and their usage will only increase. It’ll become tedious to rewrite these code sections later when porting from Delphi to Lazarus.
Title: Re: About Inline Variable
Post by: ojz0r on May 30, 2025, 09:23:21 am
Perhaps it's my inexperience, but why is inline variables desireble on a greenfield (no porting) project?
Title: Re: About Inline Variable
Post by: cdbc on May 30, 2025, 10:48:27 am
Hi
Hahaha, reminds me of this: "Just say NO to 'scripting tricks'"!!! This is PASCAL!  8-)
(...and of course drugs too)  ;D
I personally don't care about what Embarcadero does to please the 'Script-Kiddies', I don't need these 'Shenanigans' in FPC!!!!!!!
Regards Benny
Title: Re: About Inline Variable
Post by: 440bx on May 30, 2025, 11:08:14 am
The problem is the way inline variables are implemented in Delphi (which is the way they are implemented in C) but, the ability of declaring variables (and constants and types) in a location other than at the beginning of a function/procedure can significantly simplify code and make it much easier to understand.

As with most C features, it's a good feature, just as poorly implemented as they could think of.  Part for the course.
Title: Re: About Inline Variable
Post by: Martin_fr on May 30, 2025, 11:17:15 am
@cdbc: Attempt at irony? Trying to show how overuse of colors is as bad as inline vars? Zero points....




Perhaps it's my inexperience, but why is inline variables desireble on a greenfield (no porting) project?

Who says its desirable?

It may be short time convenient. I.e. for a quick and dirty project it can speed up stuff. But then in that case, dropping the need of declaration altogether will be even more efficient.
On the long road that early convenient may be a price tag that will make maintenance hell...


And for all those how bring the "only in FOR loops"... Debatable. May solve some issues, does bring others. But that has been discussed at nauseam. So go and read the existing topics, rather than repeating it here (And be certain, all and any point you may have to add, already has been debated)
Title: Re: About Inline Variable
Post by: gues1 on May 30, 2025, 11:21:13 am
The reason is simple: inline vars violate the Pascal paradigm of strict separation of declaration and implementation.
This is a good argumentation, but I think is like the famous paradigm:
"Science says that bees can't fly and therefore bees don't fly."
But the bees keep going anyway ...  :)

But anyway, Delphi has been started on that path and there will be no going back.
News, even if not contested like this one are still implemented in a long period in FPC to maintain a minimum of compatibility with Delphi, so they will certainly not be available (if ever) in the short / medium term.

(@CDBC can rest assured that he won't see this improvement any time soon  :D )
Title: Re: About Inline Variable
Post by: cdbc on May 30, 2025, 11:27:11 am
Hi gues1
Quote
(@CDBC can rest assured that he won't see this improvement any time soon  :D )
Uhhhmmmm, Me Likey  :D
Regards Benny
Title: Re: About Inline Variable
Post by: jamie on May 30, 2025, 11:54:11 am
The only use I see for it is for things like the for Loop localized variables that can't be used outside of the loop .as for C type versions ,
encapsulates every set of variables localized within a bracket ,that is messy.

Maybe those that are requesting it dont understand that its possible to have several name tags duplicated between each depth of a begin and end, just think of the mess.
Jamie
Title: Re: About Inline Variable
Post by: Thaddy on May 30, 2025, 12:34:07 pm
BTW the way Delphi implemented inline vars is not the winner of a beauty contest:
As I wrote before, loop variables can always be inferred, so why do not implement it properly, without adding the var keyword misplaced. That would  be a much cleaner implementation. I also feel such an approach has a much higher chance of being implemented.
(That does not mean I condone or support such concept, it is not Pascal)
Title: Re: About Inline Variable
Post by: Kays on May 30, 2025, 12:55:33 pm
Does FreePascal support inline variable declaration like Delphi 12? […]
Although the FPC intends to be a Delphi‐compatibile compiler (https://www.freepascal.org/faq.html#isoxpascal) and implementation of said extension has been requested in tickets #34486 (https://gitlab.com/freepascal.org/fpc/source/-/issues/34486), #34660 (https://gitlab.com/freepascal.org/fpc/source/-/issues/34660) (GitLab.com uses Cloudflare and therefore might not be accessible to you [blocking for various reasons]. GitLab.com uses GitLab and therefore might not be accessible to you [reliance on JavaScript].), the FPC does not support “inline” declarations of variables and the tickets have been turned down as “not a bug”, i. e. not a deviation from desired behavior.

NB: FreePascal – the Pascal dialect – will in all likelihood never support inline variables, but we assume you meant the FPC – the compiler with compatibility modes.
Title: Re: About Inline Variable
Post by: jamie on May 30, 2025, 03:51:33 pm
Ok lets see If I can show an example.

Code: Pascal  [Select][+][-]
  1. var
  2.  A:Integer;
  3. Begin
  4.   //.. some code;
  5.   If whatever then
  6.    Begin
  7.     Var A:integer;
  8.     //Some code
  9.    If whatever then
  10.      Begin
  11.       Var A:integer;
  12.      // some Code;
  13.     end;
  14.  End;
  15. End;
  16.  

Do we really want this confusion?

Jamie
Title: Re: About Inline Variable
Post by: Thaddy on May 30, 2025, 04:01:36 pm
No that will throw a duplicate identifier.
Title: Re: About Inline Variable
Post by: Fibonacci on May 30, 2025, 04:03:34 pm
The people who get the final say on implementing features in FPC are just against it. Not because its hard to implement (its not), not because it breaks anything (it doesnt, especially if its behind mode Delphi or a modeswitch), but simply because they dont like it.

They keep repeating the same excuses - that its unreadable, that it goes against the Pascal standard, that "its always been this way, so why change it now". Their subjective opinion (objectively wrong) ends up being the final word. FPC is missing useful features not due to technical limits, but because a few peoples tastes and ideology block the rest.

The usual FPC veterans keep backing those ideological excuses :-\

@Thaddy "inline vars violate the Pascal paradigm"
@Martin_fr "short time convenient. I.e. for a quick and dirty..."
@Thaddy "it is not Pascal"
@jamie "Do we really want this confusion?"
Title: Re: About Inline Variable
Post by: gues1 on May 30, 2025, 04:15:41 pm
Ok lets see If I can show an example.
Code: Pascal  [Select][+][-]
  1. var
  2.  A:Integer;
  3. Begin
  4.   //.. some code;
  5.   If whatever then
  6.    Begin
  7.     Var A:integer;
  8.     //Some code
  9.    If whatever then
  10.      Begin
  11.       Var A:integer;
  12.      // some Code;
  13.     end;
  14.  End;
  15. End;
  16.  
Do we really want this confusion?
Jamie
This is not legal. You cannot use variable names already used anywhere in the unit. But the proper exampleis this:
Code: Pascal  [Select][+][-]
  1. var
  2.  A:Integer;
  3. Begin
  4.   //.. some code;
  5.   for var B := 10 to 30 do
  6.     // .. same code
  7.   // here, outside the loop, B doesn't exist. Ther is not confusion.
  8.   // N.B: Delphi have insigth (like LSP) and the errors are show in the IDE during the editing, good thing.
  9. End;
  10.  
Title: Re: About Inline Variable
Post by: marcov on May 30, 2025, 04:18:22 pm
FPC is missing useful features not due to technical limits, but because a few peoples tastes and ideology block the rest.

And "The useful features" bit  is not about tasted and ideology? Come on! It is the most shallow copy-cat feature there is. Syntax makeup that doesn't make anything possible that was not possible before. The whole "pro" argument is pointless drama.

Anyway the story is roughly true. There was contention, and when that discussion was held, it seemed that the component builders mostly refrained from it, a decision was postponed. We were aware of Delphi change to  to a subscription model that forces users to newest version, and that in the long run it will probably be inevitable.

But even then, I don't see any reason to fast track it. It would be aeons till it is in releases anyway, if it were implemented in trunk now.
Title: Re: About Inline Variable
Post by: gues1 on May 30, 2025, 04:23:33 pm
I propose don't start again another "var inline" discussion.

All of us have understood tha FPC team has choosen to skip that features by now. In the future we are going to see.
But now stop this discussion.
Title: Re: About Inline Variable
Post by: Martin_fr on May 30, 2025, 04:24:01 pm
@Thaddy "inline vars violate the Pascal paradigm"
@Martin_fr "short time convenient. I.e. for a quick and dirty..."
@Thaddy "it is not Pascal"
@jamie "Do we really want this confusion?"

None of those are FPC team. None of those are decision makers for that particular issue.

I am Lazarus team => and there making mainly decisions on the Debugger (within the limits given by external factors / e.g. properties are a problem in the compiler) and SynEdit.

But, yes, a few make that decision... The few that do the work.

Then again, non of those few, and non others have made the decision that the project can't be forked by anyone who want to go a different path. Other open source projects went through that.
- So, if someone wants that feature, well no one stops them.
- But if someone wants the feature done by somebody else, then you need to convince that somebody else.
Title: Re: About Inline Variable
Post by: Fibonacci on May 30, 2025, 04:36:12 pm
And "The useful features" bit  is not about tasted and ideology? Come on!

Perhaps. But the taste of a few ends up deciding how everyone else (the majority) is allowed to write code.

It would be aeons till it is in releases anyway, if it were implemented in trunk now.

Im under the impression that most active FPC coders just use trunk anyway, so that doesnt really seem like a problem.

None of those are FPC team. None of those are decision makers for that particular issue.

They are the "FPC veterans" who keep backing the usual excuses for not implementing new features.

forked by anyone who want to go a different path

Then it becomes hard to share open source code with the community, since using or contributing to such a project would require a specific forked compiler.
Title: Re: About Inline Variable
Post by: Fibonacci on May 30, 2025, 04:38:14 pm
I propose don't start again another "var inline" discussion.

Nah! This is a battle worth fighting! >:D :D
Title: Re: About Inline Variable
Post by: Martin_fr on May 30, 2025, 04:53:42 pm
None of those are FPC team. None of those are decision makers for that particular issue.

They are the "FPC veterans" who keep backing the usual excuses for not implementing new features.

So being around for longer forbids me to voice my opinion? But you can voice yours and repeat arguments that (you or others) made before?
Title: Re: About Inline Variable
Post by: Fibonacci on May 30, 2025, 05:00:58 pm
So being around for longer forbids me to voice my opinion?

Nobody said your opinion isnt welcome, but that doesnt mean it cant be questioned or challenged.
Title: Re: About Inline Variable
Post by: Martin_fr on May 30, 2025, 05:11:09 pm
So being around for longer forbids me to voice my opinion?

Nobody said your opinion isnt welcome, but that doesnt mean it cant be questioned or challenged.

Sure. But what has that got to do with how long I have been around? Is that age-ism? My opinion isn't good because I was born to long ago? Or just about, the time I have been involved with the project? Kind of alleging that as a long time user I must be too conservative?

What has my person to do with the correctness (or opposite) of my statement?



Don't worry, I don't take it personally. I can weather worse than that. Nor will I hold it against you or anyone, I have made my own questionable statements over time.

But, well right back at you: I can question others opinion too. And I can question how they present that opinion.



As for the part about "a few ... opposing it", that hinting at it would be a minority... Well, in my view, it's a few asking for it. Seems to be the battle of the few against the few ;)
Title: Re: About Inline Variable
Post by: MarkMLl on May 30, 2025, 06:01:36 pm
I do not intend to be an active part of yet another of the interminable arguments that this community is devolving into, but:

They are the "FPC veterans" who keep backing the usual excuses for not implementing new features.

As a Pascal veteran, using the language since the early 1980s, I feel entitled to say my bit.

The rule that the index variable should be treated as having no consistent variable on normal termination of a for loop is one of the dumber things Wirth did.

The exception that the index variable can be assumed to have a consistent variable if a for loop is broken out of is one of the dumber things that whoever  introduced  break  into Pascal did.

The lack of an alias in a with, intended to indicate exactly what was being referred to, is similarly dumb: it's analogous to designing a for statement without an explicit index variable.

Using a for or with statement to declare a local variable and assign its initial value is consistent with the Pascal (and ALGOL) rule that all variables should be declared before use, provided that the scope is /precisely/ the following statement (which might, as usual, be a compound statement). Whether or not this implies a new stack frame is an implementation detail.

I fully accept that declaring a variable at an arbitrary position within a sequence of statements is anathema, and I fully accept that implicit declaration of a variable or any attempt to declare a variable without an explicit type "just ain't Pascal". And I don't give a damn if there are people in the Delphi community who think that such things are OK.

MarkMLl
Title: Re: About Inline Variable
Post by: Fibonacci on May 30, 2025, 06:27:13 pm
As a Pascal veteran

I don't give a damn if there are people in the Delphi community who think that such things are OK.

Exactly. You just proved my point.
Title: Re: About Inline Variable
Post by: marcov on May 30, 2025, 06:36:36 pm
And as there is no progress in this thread, it is now locked.
TinyPortal © 2005-2018