[Python-ideas] Short form for keyword arguments and dicts

Anders Hovmöller boxed at killingar.net
Sat Jun 22 23:01:56 CEST 2013


> Yes, but consistency, y'know. Why "bar = bar ≡ = bar" here and "bar =
> bar !≡ = bar" there?


Keyword arguments aren't the same thing as assignment. The consistency ship
has sailed and we're not on it :P


> I've skimmed a bit but I'm still unsure; why? How does Objective-C
> deal with this?


They deal with it with the nuclear option: all methods are 100% of the time
ordered AND named. Unfortunately this has the side effect of a lot of
method calls like "[foo setX:x y:y width:width height:height font:font]"
which is almost exactly the same as the worst case in python:
"foo.setStuff(x=x, y=y, width=width, height=height, font=font)".

This rather brutish approach forces a rather verbose style of writing,
which is annoying when you just want to bang out a prototype but extremely
valuable when having to maintain large code bases down the line. One of the
main points about my suggestion is that there should be almost no overhead
to using keyword arguments when just passing arguments along or when
variable names are nice and descriptive. This would create a lower barrier
to use, which in turn leads to more solid and more readable code (I hope!).


> >> There are so many more cases to cover and this doesn't fill them,
> >
> > Like what? At least name one so we can have a discussion about it!
>
> One? Well, the one above!
>
> I agree that classes seem a bit far-fetched (personally I dislike that
> syntax) but what about:
>
> def function(arg=arg):
>     ...
>
> def function(arg):
>     self.arg = arg


(Where is self defined?)


>
>
thing = dictionary[thing]
>
> and so on, which are all of the same form, albeit with different
> "surroundings". We can't just double the whole syntax of Python for
> this!


I'm not suggesting that though. It seems to me like you're taking my
suggestion in absurdum.


> Does foo(=bar) not bug you?
> Really?
>

Compared to foo(bar=bar)? No.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130622/839905ab/attachment-0001.html>


More information about the Python-ideas mailing list