On 03/02/2011 02:59 PM, Steven Schveighoffer wrote:
On Wed, 02 Mar 2011 08:45:43 -0500, Jason E. Aten <[email protected]> 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

I had never thought at that, but I'm surprised: what prevents Python's "compiler" (say, a semantic phase after parsing) to check number and names of arguments. (Number seems not to be checked before runtime neither.) All required information is in the AST. For named params, Python could translate to position params just like D. This would certainly remove a relevant amount of runtime "speed-down", I guess. (Only type-check of builtin func args must remain at runtime.)

Denis
--
_________________
vita es estrany
spir.wikidot.com

Reply via email to