5 ms·
JS'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 r
by jampekka 1y ago
JS'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.
- jampekka 1y agoLibraries like underscore are possible because of JS having composable primitives. JS has many many warts, and the for-loop is a good example of this. And the _.each is a good example how the core JS allows for working around it.
- bvrmn 1y agoBut underscore is literally a bunch of functions taking lambdas. Python also has functions and lambdas. [1] shows it could provide the same interface. I don't get what composable primitives JS has. [1]: https://pydash.readthedocs.io/en/latest/ https://pydash.readthedocs.io/en/latest/