3 ms·
Delphi has those too, and with latest iteration (read May 2020) they added inline variable declaration (which on Free Pascal will raise a syntax error)
by unnouinceput 6y ago
Delphi has those too, and with latest iteration (read May 2020) they added inline variable declaration (which on Free Pascal will raise a syntax error)
- badsectoracula 6y agoNote that inline variable declaration had been discussed at the past by the Free Pascal developers and was rejected by most of them - this is a (rare) case where they decided that they wont follow Delphi. Reasons, IIRC, are mainly due to how weird the syntax is and it feels too un-Pascal-ish to have mixed declarations and code (in Pascal pretty much everything is declared in its own section) and with Pascal supporting nested functions/procedures and the IDE being able to autocomplete variable declarations for you, it is more of a code smell than something necessary.
- unnouinceput 6y agoFrom what I've read/understood, the reason Delphi folks decided to do this is to allow even better compiler optimization. This way it's easier for optimizer to see the local variable needs to be a CPU registry and no memory access, speeding its performance.
- badsectoracula 6y agoHm, i guess this depends on the compiler, but if that was the case then first use should be enough to figure out this. I guess classic Delphi had a very simple compiler so perhaps it needs this, but AFAIK modern Delphi has an LLVM backend whose optimizations shouldn't be affected by variable placement. In any case, i think Free Pascal does have variable lifetime analysis so its optimizations shouldn't need that either.