Pretty please: Named arguments

Steven Schveighoffer schveiguy at yahoo.com
Wed Mar 2 05:59:20 PST 2011


On Wed, 02 Mar 2011 08:45:43 -0500, Jason E. Aten <j.e.aten at gmail.com>  
wrote:

> I find this an interesting discussion.  Coming from writing alot of code  
> in
> language that makes extensive and
> highly effective use of named arguments (R), I can say that optional  
> named
> arguments
> (as in Lisp, and descendants like Python and R) do have big software
> engineering benefits,
> but also come with a substantial costs in terms of complexity of the
> function call sequence.
>
> That is, named arguments can be expensive in a typical interpreted
> implementation
> (probably one reason why R and Python are much slower to execute than the
> other
> interpreted languages), presumably because each function call has to
> invoke hash
> table lookups to determine the canonical formal position of each actual
> argument, and deal with variadic
> cases, to rearrange the order of the arguments to match expectations of  
> the
> callee.
>
> Someone familiar with lisp compilers could probably tell you if the heavy
> speed tax is intrinsic
> or just the price of interpretation.
>
> It would indeed be an interesting challenge to see if the compile-time
> metaprogramming
> features of D would allow one to include named arguments in an opt-in
> fashion without speed reduction.

Considering that calling a function with parameters by name directly  
translates at compile time to a function call by position, there should be  
zero speed impact.  The interpretation of the parameter names, which is  
done at runtime for Python, would be done at compile time in D.

-Steve


More information about the Digitalmars-d mailing list