Re: [fpc-pascal] named parameter

2017-05-29 Thread Sven Barth via fpc-pascal
Am 29.05.2017 10:26 schrieb "Ryan Joseph" :
>
>
> > On May 29, 2017, at 1:01 PM, Sven Barth via fpc-pascal <
fpc-pascal@lists.freepascal.org> wrote:
> >
> > If anything like this would be implemented, then the already existing
syntax (for variant dispatch calls) would be used which uses ":=".
> >
> >
>
> What are variant dispatch calls? Maybe something from Delphi I’m not
familiar with.

It's usually used in the context of OLE automation though one could also
use this with independently of OLE/COM.
For an example see here:
https://www.freepascal.org/~michael/articles/word/word.pdf

> That’s too bad, a single colon matches the declaration better and looks
nice.

An assignment is the logical choice cause you're assigning a value to a
parameter. A colon is used for a declaration, which is a completely
different kind of "operation".

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-29 Thread Mark Morgan Lloyd

On 29/05/17 05:15, Ryan Joseph wrote:

On May 28, 2017, at 5:22 PM, Mark Morgan Lloyd  wrote:> >> IMO 
though it does improve readability in long functions with lots of>> parameters, like windows api style 
procedures that have 5 or more>> parameters and you can't figure out which param is>> which>

You mean like this?
function Foo (theString: string; options: set of TFoo): boolean;beginend;
Foo(theString: 'foo', options: []);
Objective-C has this mandatory and it made for stupidly long method names that 
just looked terrible but it was optional Pascal makes it look nicer. The 
declaration syntax is already the same as the label for the calling syntax so 
that seems like a nice fit.


Except that there's no provision for setting a parameter passed as a set 
element to true if it's not given explicitly. Sometimes you want that, 
and simply inverting the meaning of a parameter results in values which 
appear contrived in the context of the "real world" problem being solved.


The example I gave was from a terminal emulator, where "echo", 
"loopback" and so on are well-accepted concepts in the industry. And 
having a parameter "any_character_set_as_long_as_its_not_apl" is 
downright silly :-)


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-29 Thread Ryan Joseph

> On May 29, 2017, at 1:01 PM, Sven Barth via fpc-pascal 
>  wrote:
> 
> If anything like this would be implemented, then the already existing syntax 
> (for variant dispatch calls) would be used which uses ":=".
> 
> 

What are variant dispatch calls? Maybe something from Delphi I’m not familiar 
with. 

That’s too bad, a single colon matches the declaration better and looks nice. 

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-29 Thread Sven Barth via fpc-pascal
Am 29.05.2017 07:13 schrieb "Ryan Joseph" :
>
>
> > On May 28, 2017, at 5:22 PM, Mark Morgan Lloyd <
markmll.fpc-pas...@telemetry.co.uk> wrote:
> >
> >> IMO though it does improve readability in long functions with lots of
> >> parameters, like windows api style procedures that have 5 or more
> >> parameters and you can't figure out which param is
> >> which
> >
>
> You mean like this?
>
> function Foo (theString: string; options: set of TFoo): boolean;
> begin
> end;
>
> Foo(theString: 'foo', options: []);
>
> Objective-C has this mandatory and it made for stupidly long method names
that just looked terrible but it was optional Pascal makes it look nicer.
The declaration syntax is already the same as the label for the calling
syntax so that seems like a nice fit.

If anything like this would be implemented, then the already existing
syntax (for variant dispatch calls) would be used which uses ":=".

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-28 Thread Ryan Joseph

> On May 28, 2017, at 5:22 PM, Mark Morgan Lloyd 
>  wrote:
> 
>> IMO though it does improve readability in long functions with lots of
>> parameters, like windows api style procedures that have 5 or more
>> parameters and you can't figure out which param is
>> which
> 

You mean like this?

function Foo (theString: string; options: set of TFoo): boolean;
begin
end;

Foo(theString: 'foo', options: []);

Objective-C has this mandatory and it made for stupidly long method names that 
just looked terrible but it was optional Pascal makes it look nicer. The 
declaration syntax is already the same as the label for the calling syntax so 
that seems like a nice fit.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-28 Thread Marco van de Voort
In our previous episode, Bernd Oppolzer said:
> IMO, it's not about named parameters;
> furthermore, it is not about readability, but this IMO
> is a maintenance issue.
> 
> Think about a procedure that has two parameters and a lot of callers
> and you want to add a third one.
> 
> it would be nice if you could specify a default value for the new
> third parameter and don't have to change all the callers that use
> only two.

Yes, that is why Visual Basic had it, but I thought the whole concept was
nowadays considered old fashioned and baroque.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-28 Thread Mark Morgan Lloyd

On 27/05/17 20:30, nore...@z505.com wrote:


IMO though it does improve readability in long functions with lots of
parameters, like windows api style procedures that have 5 or more
parameters and you can't figure out which param is
which


I had an interesting case a couple of years ago where a procedure called 
itself recursively, but with a couple of the parameters shifted in 
relative position. Messing that up when I added an extra parameter 
caused a difficult-to find bug, so I think that some sort of 
identify-by-name arrangment (I'm not saying pass-by-name because of its 
historical meaning) would be useful.


procedure SendMechCodeToLineASCII(mc: word; bcd, apl: boolean; crlf: 
boolean= false;
lf: boolean= false; echo: boolean= false; 
loopback: boolean= false);


..

(* CR expansion, local echo etc. Note recursive echo of LF if CR is 
expanded,   *)
(* this is to keep the VM/CMS "Sixpack" happy since otherwise the first 
line of *)
(* output always tries to overwrite the command that instigated it (but 
with*)
(* bits of the command showing through non-destructive spaces). 
   *)
(* 
   *)
(* Note intentional shift of parameter positions in the recursive call 
below.   *)


if (mc = Op_CarrierReturn) and crlf then
  SendMechCodeToLineASCII(Op_Index, bcd, apl, {crlf :=} loopback, 
{lf :=} false,
{echo := } true, {loopback :=} 
false);

if echo then
  PseudoEventQueue.Enqueue($8000 + canonical(mc))
  end
end { SendMechCodeToLineASCII } ;

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-28 Thread Ewald
On 27/05/17 11:26, Bernd Oppolzer wrote:
> it would be nice if you could specify a default value for the new
> third parameter and don't have to change all the callers that use
> only two.
> 
[snip]
> procecure P (x : integer; y : boolean; c: char := ' ');
> 
> the first two parameters are mandatory, the third is optional.
> Calls to P with 2 and 3 parameters are both valid.

You realize you can already do this, right?

See https://www.freepascal.org/docs-html/ref/refsu64.html#x176-19800014.4.1


-- 
Ewald
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Graeme Geldenhuys

On 2017-05-27 21:14, nore...@z505.com wrote:

f(p3 := true);
;

You can do something similar already with source comments

SomeProc(true {p3})


That will not work. p3 in his example is the 3rd parameter. You are only 
passing one parameter, so that will then become p1's value. And if the 
types don't match, you'll get a compiler error.


Optional parameters can only be at the end of the parameter list, and 
always from left-to-right.


Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread noreply

On 2017-05-27 01:17, Mr Bee via fpc-pascal wrote:

Hi,

As Pascal mostly well known as a safe, easy to read, and elegant
language, don't you think Pascal needs named parameter? I mean for ALL
kind of parameters, not just for Variants. When you have a function
with many parameters having default values, you know that named
parameter is desirable. For example:

function f(p1: string = ''; p2: integer = 0; p3: boolean = false);

But you only need to supply the third parameter, you still must supply
the first and second ones with appropriate default values, like this:

f('', 0, true);

while with named parameter, you can do this:

f(p3 := true);
;


You can do something similar already with source comments

SomeProc(true {p3})

or

SomeProc({p3} true);

But obviously the compiler doesn't check it.

Problem is it increases the verbosity of the code, and how would the 
compiler determine when to check these and when not to... If you check 
this all the time it makes the language much more verbose and tedious 
for small functions like inttostr that you use all the time.


IMO though it does improve readability in long functions with lots of 
parameters, like windows api style procedures that have 5 or more 
parameters and you can't figure out which param is which

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Sven Barth via fpc-pascal
2017-05-27 16:12 GMT+02:00 Michael Van Canneyt :
>
>
> On Sat, 27 May 2017, Sven Barth via fpc-pascal wrote:
>
>> 2017-05-27 9:54 GMT+02:00 Michael Van Canneyt :
>>>
>>>
>>>
>>> On Sat, 27 May 2017, Mr Bee via fpc-pascal wrote:
>>>
 Hi,

 As Pascal mostly well known as a safe, easy to read, and elegant
 language,
 don't you think Pascal needs named parameter? I mean for ALL kind of
 parameters, not just for Variants. When you have a function with many
 parameters having default values, you know that named parameter is
 desirable. For example:

 function f(p1: string = ''; p2: integer = 0; p3: boolean = false);

 But you only need to supply the third parameter, you still must supply
 the
 first and second ones with appropriate default values, like this:

 f('', 0, true);

 while with named parameter, you can do this:

 f(p3 := true);

 I believe it would raise Pascal's code readability. I know it has been
 discussed before. I know somehow the parser had been able to read such
 syntax. So, why don't we have the option to enable it for people who
 want
 it? Kinda a syntax switch mode.

 What do you think? :)
>>>
>>>
>>>
>>>
>>> Opinions on what constitutes readable code clearly differ :)
>>>
>>> But as far as I know, the parser is not able to read this syntax ?
>>
>>
>> The parser supports it for dispatch calls on variants (both methods
>> and properties). You even wrote that in your own article about Word
>> automation: https://www.freepascal.org/~michael/articles/word/word.pdf
>> ;)
>
>
> Yes, in Delphi. But I didn't know FPC also supports it ?

Yes, it does. I didn't find a testcase for it right away, but the
compiler definitely contains code for this.

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Michael Van Canneyt



On Sat, 27 May 2017, Sven Barth via fpc-pascal wrote:


2017-05-27 9:54 GMT+02:00 Michael Van Canneyt :



On Sat, 27 May 2017, Mr Bee via fpc-pascal wrote:


Hi,

As Pascal mostly well known as a safe, easy to read, and elegant language,
don't you think Pascal needs named parameter? I mean for ALL kind of
parameters, not just for Variants. When you have a function with many
parameters having default values, you know that named parameter is
desirable. For example:

function f(p1: string = ''; p2: integer = 0; p3: boolean = false);

But you only need to supply the third parameter, you still must supply the
first and second ones with appropriate default values, like this:

f('', 0, true);

while with named parameter, you can do this:

f(p3 := true);

I believe it would raise Pascal's code readability. I know it has been
discussed before. I know somehow the parser had been able to read such
syntax. So, why don't we have the option to enable it for people who want
it? Kinda a syntax switch mode.

What do you think? :)




Opinions on what constitutes readable code clearly differ :)

But as far as I know, the parser is not able to read this syntax ?


The parser supports it for dispatch calls on variants (both methods
and properties). You even wrote that in your own article about Word
automation: https://www.freepascal.org/~michael/articles/word/word.pdf
;)


Yes, in Delphi. But I didn't know FPC also supports it ?

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Sven Barth via fpc-pascal
2017-05-27 9:54 GMT+02:00 Michael Van Canneyt :
>
>
> On Sat, 27 May 2017, Mr Bee via fpc-pascal wrote:
>
>> Hi,
>>
>> As Pascal mostly well known as a safe, easy to read, and elegant language,
>> don't you think Pascal needs named parameter? I mean for ALL kind of
>> parameters, not just for Variants. When you have a function with many
>> parameters having default values, you know that named parameter is
>> desirable. For example:
>>
>> function f(p1: string = ''; p2: integer = 0; p3: boolean = false);
>>
>> But you only need to supply the third parameter, you still must supply the
>> first and second ones with appropriate default values, like this:
>>
>> f('', 0, true);
>>
>> while with named parameter, you can do this:
>>
>> f(p3 := true);
>>
>> I believe it would raise Pascal's code readability. I know it has been
>> discussed before. I know somehow the parser had been able to read such
>> syntax. So, why don't we have the option to enable it for people who want
>> it? Kinda a syntax switch mode.
>>
>> What do you think? :)
>
>
>
> Opinions on what constitutes readable code clearly differ :)
>
> But as far as I know, the parser is not able to read this syntax ?

The parser supports it for dispatch calls on variants (both methods
and properties). You even wrote that in your own article about Word
automation: https://www.freepascal.org/~michael/articles/word/word.pdf
;)

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Ryan Joseph

> On May 27, 2017, at 5:29 PM, Mark Morgan Lloyd 
>  wrote:
> 
> I was on the periphery of that discussion, since I thought I needed something 
> similar (but turned out not to). But you might have noticed some of the 
> APLisms that I horrify Sven with on occasion...

I remember he liked my idea to use TPoint(x: 1; y: 2); using the record name as 
the identifier. I swear I’d add this if I knew how. :)

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Mark Morgan Lloyd

On 27/05/17 10:20, Ryan Joseph wrote:

On May 27, 2017, at 5:13 PM, Mark Morgan Lloyd  
wrote:> > someFunction(TPoint(X:0.0; Y:0.0));> > Pascal purists would probably object 
to that style, since what it's effectively doing is passing the parameters as an explicit list.

I mentioned this form of “default constructor" as a sorely missing feature in 
FPC a couple weeks ago. Making redundant constructors for records constantly is 
pretty silly. If I could figure out the compiler code I would add this myself since 
it’s probably one of the easier things to implement.


End of last month actually, I checked :-)

I was on the periphery of that discussion, since I thought I needed 
something similar (but turned out not to). But you might have noticed 
some of the APLisms that I horrify Sven with on occasion...


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Ryan Joseph

> On May 27, 2017, at 5:13 PM, Mark Morgan Lloyd 
>  wrote:
> 
> someFunction(TPoint(X:0.0; Y:0.0));
> 
> Pascal purists would probably object to that style, since what it's 
> effectively doing is passing the parameters as an explicit list.

I mentioned this form of “default constructor" as a sorely missing feature in 
FPC a couple weeks ago. Making redundant constructors for records constantly is 
pretty silly. If I could figure out the compiler code I would add this myself 
since it’s probably one of the easier things to implement.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Mark Morgan Lloyd

On 27/05/17 09:40, Ryan Joseph wrote:

On May 27, 2017, at 4:27 PM, Graeme Geldenhuys  
wrote:> > Yeah, that was going to be my suggestion too. I've done this many times 
when many parameters are optional. Use a record as parameter type. The other benefit of 
this is that it is future and backwards compatible. You can add or change parameters 
without breaking the method signature.

can you show an example of this? Just curious.


IIRC the problem is that while it's possible to initialise a record 
constant by named fields processed in arbitrary order, the compiler at 
present doesn't allow it to be done inline:


someFunction(TPoint(X:0.0; Y:0.0));

Pascal purists would probably object to that style, since what it's 
effectively doing is passing the parameters as an explicit list.


Somebody please correct me it I'm wrong.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Martin Schreiber
On Saturday 27 May 2017 11:30:38 Ryan Joseph wrote:
>
> can you show an example of this? Just curious.
>
In MSEgui most of the public widget methods an method properties use this 
approach.
"
type
 keyeventinfoty = record
  eventkind: eventkindty;
  key,keynomod: keyty;
  chars: msestring;
  shiftstate: shiftstatesty;
  eventstate: eventstatesty;
  timestamp: longword; //usec
 end;
[...]
 twidget = class(tactcomponent,iscrollframe,iface,iassistiveclient)
[...]
   procedure dokeydown(var info: keyeventinfoty); virtual;
"
"
type
 tactionwidget = class(twidget)
[...]
   property onkeydown: keyeventty read fonkeydown write fonkeydown;

"
https://gitlab.com/mseide-msegui/mseide-msegui/blob/master/lib/common/kernel/msegui.pas
https://gitlab.com/mseide-msegui/mseide-msegui/blob/master/lib/common/widgets/msewidgets.pas

Martin
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Bernd Oppolzer

IMO, it's not about named parameters;
furthermore, it is not about readability, but this IMO
is a maintenance issue.

Think about a procedure that has two parameters and a lot of callers
and you want to add a third one.

it would be nice if you could specify a default value for the new
third parameter and don't have to change all the callers that use
only two.

So IMO a sensible extension to the Pascal syntax could be:

if there is a initialization on the procedure declaration, the parameter
is optional.

Example:

procecure P (x : integer; y : boolean; c: char := ' ');

the first two parameters are mandatory, the third is optional.
Calls to P with 2 and 3 parameters are both valid.

Another extension would be:

specify the formal parameter's name on call, that is:

P (y := true, c := '*', x := 25);

which allows for a different sequence of arguments on the procedure call

but this is a different topic and should be discussed seperate from the
default issue.

I guess, that all this will be limited to byvalue parameters ... not for
var parameters ...

Kind regards

Bernd


Am 27.05.2017 um 08:17 schrieb Mr Bee via fpc-pascal:

Hi,

As Pascal mostly well known as a safe, easy to read, and elegant 
language, don't you think Pascal needs named parameter? I mean for ALL 
kind of parameters, not just for Variants. When you have a function 
with many parameters having default values, you know that named 
parameter is desirable. For example:


function f(p1: string = ''; p2: integer = 0; p3: boolean = false);

But you only need to supply the third parameter, you still must supply 
the first and second ones with appropriate default values, like this:


f('', 0, true);

while with named parameter, you can do this:

f(p3 := true);

I believe it would raise Pascal's code readability. I know it has been 
discussed before. I know somehow the parser had been able to read such 
syntax. So, why don't we have the option to enable it for people who 
want it? Kinda a syntax switch mode.


What do you think? :)

--

Regards,


–Mr Bee


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Ryan Joseph

> On May 27, 2017, at 4:27 PM, Graeme Geldenhuys 
>  wrote:
> 
> Yeah, that was going to be my suggestion too. I've done this many times when 
> many parameters are optional. Use a record as parameter type. The other 
> benefit of this is that it is future and backwards compatible. You can add or 
> change parameters without breaking the method signature.

can you show an example of this? Just curious.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Graeme Geldenhuys

On 2017-05-27 09:47, Mark Morgan Lloyd wrote:

It would probably be possible to do it by using a record with nullable
fields as the parameter.


Yeah, that was going to be my suggestion too. I've done this many times 
when many parameters are optional. Use a record as parameter type. The 
other benefit of this is that it is future and backwards compatible. You 
can add or change parameters without breaking the method signature.


Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Mark Morgan Lloyd

On 27/05/17 08:00, Michael Van Canneyt wrote:

On Sat, 27 May 2017, Mr Bee via fpc-pascal wrote:

Hi,>> As Pascal mostly well known as a safe, easy to read, and elegant
language,> don't you think Pascal needs named parameter? I mean for
ALL kind of> parameters, not just for Variants. When you have a
function with many> parameters having default values, you know that
named parameter is> desirable. For example:>> function f(p1: string =
''; p2: integer = 0; p3: boolean = false);>> But you only need to
supply the third parameter, you still must supply the> first and
second ones with appropriate default values, like this:>> f('', 0,
true);>> while with named parameter, you can do this:>> f(p3 :=
true);>> I believe it would raise Pascal's code readability. I know it
has been> discussed before. I know somehow the parser had been able to
read such> syntax. So, why don't we have the option to enable it for
people who want> it? Kinda a syntax switch mode.>> What do you think? :)


Opinions on what constitutes readable code clearly differ :)
But as far as I know, the parser is not able to read this syntax ?


It would probably be possible to do it by using a record with nullable 
fields as the parameter.


Otherwise if you want that sort of thing use Smalltalk :-)

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] named parameter

2017-05-27 Thread Michael Van Canneyt



On Sat, 27 May 2017, Mr Bee via fpc-pascal wrote:


Hi,

As Pascal mostly well known as a safe, easy to read, and elegant language,
don't you think Pascal needs named parameter? I mean for ALL kind of
parameters, not just for Variants. When you have a function with many
parameters having default values, you know that named parameter is
desirable. For example:

function f(p1: string = ''; p2: integer = 0; p3: boolean = false);

But you only need to supply the third parameter, you still must supply the
first and second ones with appropriate default values, like this:

f('', 0, true);

while with named parameter, you can do this:

f(p3 := true);

I believe it would raise Pascal's code readability. I know it has been
discussed before. I know somehow the parser had been able to read such
syntax. So, why don't we have the option to enable it for people who want
it? Kinda a syntax switch mode.

What do you think? :)



Opinions on what constitutes readable code clearly differ :)

But as far as I know, the parser is not able to read this syntax ?

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

[fpc-pascal] named parameter

2017-05-27 Thread Mr Bee via fpc-pascal
Hi,

As Pascal mostly well known as a safe, easy to read, and elegant language,
don't you think Pascal needs named parameter? I mean for ALL kind of
parameters, not just for Variants. When you have a function with many
parameters having default values, you know that named parameter is
desirable. For example:

function f(p1: string = ''; p2: integer = 0; p3: boolean = false);

But you only need to supply the third parameter, you still must supply the
first and second ones with appropriate default values, like this:

f('', 0, true);

while with named parameter, you can do this:

f(p3 := true);

I believe it would raise Pascal's code readability. I know it has been
discussed before. I know somehow the parser had been able to read such
syntax. So, why don't we have the option to enable it for people who want
it? Kinda a syntax switch mode.

What do you think? :)

-- 

Regards,


–Mr Bee
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal