5 ms·
I like keyword-only arguments, but they become tedious too quickly - especially when the variable names already match (fn(x=x, y=y, z=z)). I wish Python had Jav
by ayhanfuat 1y ago
I like keyword-only arguments, but they become tedious too quickly - especially when the variable names already match (fn(x=x, y=y, z=z)). I wish Python had JavaScript’s shorthand property syntax. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#property_definitions https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...).
- sweetgiorni 1y agoPython 3.14 adds that shorthand, but with a slight different (and IMO uglier) syntax: fn(x=,y=,z=) https://peps.python.org/pep-0736/ https://peps.python.org/pep-0736/ edit: nevermind, that PEP was rejected :/
- pansa2 1y agoThat PEP says “rejected”
- snickerdoodle12 1y agoThankfully so. As much as I want a shorthand, this syntax wasn't it.
- deleted 1y ago[deleted]
- vovavili 1y agoBy the look of it, the feeling I get is that a decent and convenient syntax proposal has been bikeshedded into rejection. Some particular form of keyword arguments at invocation would definitely make quite a few of my scripts more readable.
- dgan 1y agothere should definitely be an ocaml-like equivalent of "~argument"
- toolslive 1y agoit's also a gentle force towards consistent naming, ie having the same name on caller and callee site.
- jampekka 1y agoJS's shorthand property syntax is lovely and elegant. Python can't really adopt it though as it clashes with the set syntax (which is such a niche use case it really shouldn't have a special syntax). You could do something like f(**{x, y, z}) with just that. Not the prettiest, but at least it would be DRY. But in general Python devs seem to prefer "explicit" ad-hoc syntax for each use case instead of composable "primitives". Which is approaching a kind of C++ situation where relatively few users know the syntax comprehensively.
- data-ottawa 1y agoJulia uses a semicolon prefix in a tuple to denote this restructuring. I think that could fit into Python without breaking the whole ecosystem.
- bobbylarrybobby 1y agoPython would probably just use the asterisk to mimic the syntax used to declare kw-only kwargs. def f(x, , y): ... f(foo, , y)
- bvrmn 1y ago> But in general Python devs seem to prefer "explicit" ad-hoc syntax for each use case instead of composable "primitives". I hope you don't consider JS having "composable primitives". To backup my point: there is no anything similar to underscore-like libraries for Python. All is covered by stdlib and syntax. > for(in) / for(of) Cough, cough.