Default parameter values for methods

From: Matan Vax <matan_at_.....>
Date: Wed Jun 10 2009 - 10:54:19 PDT
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, and is
believed to be clean.
Received on Wed Jun 10 10:57:00 2009

This archive was generated by hypermail 2.1.8 : Wed Jun 10 2009 - 10:57:07 PDT