RE: Default parameter values for methods

From: <Serrie.Chapman_at_.....>
Date: Thu Jun 11 2009 - 01:51:26 PDT
Hi Matan,

I agree that this sounds good.  I think some of the languages treat this differently though.

I guess theres the option where you can call

my_method(FALSE);
with the one parameter and it will always match the first x numbers of parameters.

also theres the stricter languages which only accept the methods with the matching number of parameters so they can have multiple instantiations of the same method name (overloading)

my_method(a: bool, b: bool) {
};
my_method(a: bool, b: bool,c:bool) {
};

I'm not sure if there is also a way of calling the method and telling it if there was only one specific parameter that you wanted to pass - for example

my_method(a: bool, b: bool,c:bool) {
};

my_method(X,X,FALSE);
to just overide the third parameter.

but it certainly sounds like a good idea to implement it within the language.

Cheers
Serrie
________________________________
From: Galpin Darren (IFGB AIM MCD CV)
Sent: Thursday, June 11, 2009 7:47 AM
To: 'Matan Vax'; 'ieee1647@server.eda.org'
Subject: RE: Default parameter values for methods

Hi Matan,

It seems like a good idea, but I have a few questions about this, as I may be misunderstanding a few things.

Firstly, you have a method, such as:-

a: default=TRUE; -- An example, syntax will obviously be different
b: default=FALE; -- As above.
my_method(a: bool, b: bool) {
};

Normally you would then call the method as follows:-

my_method(TRUE, FALSE);

Which is fine, but if you do not provide all of the parameters, then what happens in the following case:-

my_method(FALSE);

Which of the two boolean parameters have I set, and which of the two have I missed? It isn't clear to me from the description how this would operate.

Perhaps others could comment? Should we include it?

Cheers,

Darren

________________________________
From: owner-ieee1647@server.eda.org [mailto:owner-ieee1647@server.eda.org] On Behalf Of Matan Vax
Sent: Wednesday, June 10, 2009 6:54 PM
To: ieee1647@server.eda.org
Subject: Default parameter values for methods

Hello all,

As you probably know, many object-oriented languages allow declaring default values for method parameters. Specifically in our domain both SystemC (C++) and SystemVerilog support it. The principle is simple - if a default value is designated for some parameter in the method declaration providing the parameter in the call becomes optional. If provided, the user's parameter overrides the default, and otherwise the default is passed to the method body. Upon method call parameters are resolved in order, so all parameters with defaults must be placed at the end of the parameter list.

This mechanism can be used to simplify functional APIs of core libraries, verification IPs, and other packages. When introducing some operation, library designers often face the dilemma of either defining a single method and forcing the user to provide all possible parameters, including trivial ones (NULL, UNDEF, 0, or whatever the natural default happens to be), or defining multiple method variants with different parameter sets, each with its own name. Both obscure the natural semantics of the operation. Note that method overloading may have similar impact, but is much more complicated to define and implement.

So I propose we consider adding this capability to the e standard (and obviously implement it in tools, Specman in particular). Defining it formally is relatively straightforward and I volunteer to do it if I get green light from this forum.

What do you say?
Matan.


--
This message has been scanned for viruses and
dangerous content by MailScanner<http://www.mailscanner.info/>, and is
believed to be clean.

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Thu Jun 11 02:21:32 2009

This archive was generated by hypermail 2.1.8 : Thu Jun 11 2009 - 02:21:37 PDT