[IronPython] Keyword arguments

Brian Quinlan brian at sweetapp.com
Thu Aug 26 14:19:01 CEST 2004


Jim Hugunin wrote:
> I really like this feature and it's unlikely that it will disappear in the
> future without a strong argument. I originally designed it for Jython as
> the way that I could make code using swing as easy to write as TkInter code.
> I think it serves that same purpose to make Windows.Forms or GTK# code
> friendlier to scripting.  This is one of the ideas in Jython that the groovy
> developers liked enough to borrow for their language.

I actually like the feature as well. A lot of .NET Framework
constructors are option-starved and this is a reasonable way of working
around this problem. Of coures you could write a simple function to do
this as well (maybe make it a built-in).

def create_and_set(type, *args, **kws): # XXX need better name
     i = type(*args)
     for k, v in kws.items: setattr(i, k, v)
     return i

create_and_set(Form, Location=Point(2,3), ...) OR
construct(Form, Location=Point(2,3), ...) OR
ctor(Form, Location=Point(2,3), ...) OR
build(Form, Location=Point(2,3), ...) OR
create(Form, Location=Point(2,3), ...)

I'm not sure that I like any of those names but the syntax seems
reasonable and the semantics are easily understood by the Python
programmer.

> This is NOT a change to CPython's semantics.  Keyword arguments are used to
> allow the initialization of attributes (and fields) only for code from
> standard CLR libraries that weren't designed with Python or any scripting
> language in mind.  Constructors for Python classes should continue to behave
> exactly as they do in CPython.

I'm not sure how you can argue that this is not a semantic change. CLR
method signatures look a lot like regular Python signatures (with the 
addition of type information). You are imposing two different semantics 
that the user has to remember i.e. when you are calling a Python 
method, keywords arguments mean THIS but when calling a CLR method 
keyword arguments mean THAT. This is a technically unnecessary 
distinction. And what happens if I get a compiled Python assembly from 
someone - what do keywords mean in that case? Either way it will be 
confusing.

I'm probably not smart enough to effectively make this argument - I'll
try to recruit someone smarter who agrees with me if you need more
encouragement.

Cheers,
Brian




More information about the Ironpython-users mailing list