Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-12

Idea/question about a language (syntax) extension

12 messages · 6 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Flávio Etrusco

Hi all,
I want to propose a syntax extension for the compiler to check parameters' name on function/procure calls. Would such a patch be accepted? Does anybody have a suggestion for the syntax? (i guess something along the line of a compiler directive to go together with the parameter value to avoid syntax incompatibility...)

Rationale:
I guess it's in "everybody"s interest to make auto-generated code and code refactor more robust; For example, when populating DTOs (data transfer objects) one have two options: assign each field by name and run the risk of "forgetting" to initialize some field, or make a constructor/initializer method and run the risk of changing order of parameters of the same type.
What do you think? Any alternatives?

Best regards,
Flávio

Reply by email

Paul Ishenin
to Flávio Etrusco
Flávio Etrusco wrote 6 lines
Hi all, I want to propose a syntax extension for the compiler to check parameters' name on function/procure calls. Would such a patch be accepted? Does anybody have a suggestion for the syntax? (i guess something along the line of a compiler directive to go together with the parameter value to avoid syntax incompatibility...)

You mean something like Basic has:

CallSomething(Arg1=10, Arg2='Test') ?

Best regards,
Paul Ishenin.

Reply by email

Flávio Etrusco
to Paul Ishenin
Paul Ishenin wrote 16 lines
22.12.2009 11:30, Flávio Etrusco wrote: > > Hi all, > I want to propose a syntax extension for the compiler to check > parameters' name on function/procure calls. Would such a patch be > accepted? Does anybody have a suggestion for the  syntax? (i guess > something along the line of a compiler directive to go together with > the parameter value to avoid syntax incompatibility...) You mean something like Basic has: CallSomething(Arg1=10, Arg2='Test') ? Best regards, Paul Ishenin.
Paul Ishenin wrote 16 lines
22.12.2009 11:30, Flávio Etrusco wrote: > > Hi all, > I want to propose a syntax extension for the compiler to check > parameters' name on function/procure calls. Would such a patch be > accepted? Does anybody have a suggestion for the syntax? (i guess > something along the line of a compiler directive to go together with > the parameter value to avoid syntax incompatibility...) You mean something like Basic has: CallSomething(Arg1=10, Arg2='Test') ? Best regards, Paul Ishenin.

Exactly! I didn't know/remember Basic had that. Oh well, another feature I'll have to appreciate in VB (along with the - shell-like, but poorly implemented - "begin block by default" and specific block closers) despite my despise for the language ;-)

-Flávio

Reply by email

Alexander Klenin
to Paul Ishenin: You mean something like Basic has: CallSomething(Arg1=10, Arg2='Test') ? Paul Ishenin.
Paul Ishenin wrote 12 lines
22.12.2009 11:30, Flávio Etrusco wrote: > > Hi all, > I want to propose a syntax extension for the compiler to check > parameters' name on function/procure calls. Would such a patch be > accepted? Does anybody have a suggestion for the  syntax? (i guess > something along the line of a compiler directive to go together with > the parameter value to avoid syntax incompatibility...) You mean something like Basic has: CallSomething(Arg1=10, Arg2='Test') ?

I'd say rather something like

CallSomething(Arg1:=10, Arg2:='Test')

which is already sort-of-supported by Delphi for automation classes:

http://stackoverflow.com/questions/885942/named-optional-parameters-in-delphi

Extending such support to native procedures and functions would be, in my opinion, a good idea.

Alexander S. Klenin

Reply by email

Flávio Etrusco
to Alexander Klenin
Alexander Klenin wrote 27 lines
On Tue, Dec 22, 2009 at 14:42, Paul Ishenin wrote: > 22.12.2009 11:30, Flávio Etrusco wrote: >> >> Hi all, >> I want to propose a syntax extension for the compiler to check >> parameters' name on function/procure calls. Would such a patch be >> accepted? Does anybody have a suggestion for the  syntax? (i guess >> something along the line of a compiler directive to go together with >> the parameter value to avoid syntax incompatibility...) > > You mean something like Basic has: > > CallSomething(Arg1=10, Arg2='Test') ? I'd say rather something like CallSomething(Arg1:=10, Arg2:='Test') which is already sort-of-supported by Delphi for automation classes: http://stackoverflow.com/questions/885942/named-optional-parameters-in-delphi Extending such support to native procedures and functions would be, in my opinion, a good idea. -- Alexander S. Klenin

Hmm. Does it allow to pass parameter out of the declared order? I just wanted the check for the correct parameter, but I'm sure people will then want the additional feature... :-/ Not to mention that with this syntax some people may think FPC is allowing C-like assignment-with-result :-o
(And maybe we'd want something to make it clear we're talking about destination parameters, not some clashing local variable/paramter...)

-Flávio

Reply by email

Flávio Etrusco
to Jonas Maebe: FPC also already supports it in that scenario. Jonas
Jonas Maebe wrote 16 lines
On 22 Dec 2009, at 06:27, Alexander Klenin wrote: > I'd say rather something like > > CallSomething(Arg1:=10, Arg2:='Test') > > which is already sort-of-supported by Delphi for automation classes: > > > http://stackoverflow.com/questions/885942/named-optional-parameters-in-delphi FPC also already supports it in that scenario. Jonas

Interesting. I guess this situation is little easier because the way Automation procedure calls pass parameters, right? But what's your opinion on extending it to standard procedures?

Best regards,
Flávio

Reply by email

Jonas Maebe
to Flávio Etrusco
Flávio Etrusco wrote 17 lines
On Tue, Dec 22, 2009 at 6:34 AM, Jonas Maebe < > wrote: > > On 22 Dec 2009, at 06:27, Alexander Klenin wrote: > >> I'd say rather something like >> >> CallSomething(Arg1:=10, Arg2:='Test') >> >> which is already sort-of-supported by Delphi for automation classes: >> >> http://stackoverflow.com/questions/885942/named-optional-parameters-in-delphi > > FPC also already supports it in that scenario. Interesting. I guess this situation is little easier because the way Automation procedure calls pass parameters, right?

I have no idea. I know it exists, but I have no clue at all about how it works.

But what's your opinion on extending it to standard procedures?

I have no opinion on that.

Jonas

Reply by email

Flávio Etrusco
to Florian Klaempfl
Florian Klaempfl wrote 6 lines
Flávio Etrusco schrieb: >  But what's your > opinion on extending it to standard procedures? I see no sense in doing so.

Do you mean this syntax or the feature at all? Do you know another way to solve or help the problem I proposed? Would you prefer implementing another feature (e.g. class or method versioning) instead?

Best regards,
Flávio

Reply by email