2 ms·
I think: data Point3D(x, y, z) from Vector: ... is a terrible syntax, there are plenty of legitimate use cases where you'd have an overwhelming amount of
by rollcat 4y ago
I think:
data Point3D(x, y, z) from Vector: ...
is a terrible syntax, there are plenty of legitimate use cases where you'd have an overwhelming amount of fields in a class/structure, and listing them line by line (as well as explicitly specifying accessors to handle the couple special cases) would end up much more readable. I'd rather see something more along these lines:
data Parrot(Animal):
name
age: int
alive: bool = False
purchased_in: Shop | None = field(default_factory=get_shop)
...
(Move "field" to builtins, etc.)
But overall this proposal seems like a no-brainer, even before the addition of the match statement. The "classic" __init__ is a jarring violation of DRY, baked right into one of the most common idioms in the language, and gets in the way of not just the "QoL" features like destructuring or type checking, but also of the efforts to build more efficient implementations that could pre-allocate object memory without speculative analysis, or optimise the dict lookup away.
The question is not "shall we", but "why wasn't it done in 2008".
- JohnDeHope 4y agoYou made me think "I think: [all of python] is a terrible syntax". At some point in the past, python crossed over into perl or php territory for me. The semantics, runtime, culture, support, library availability, etc. are all great. But jiminy no syntax can keep up with the decades of layers of cruft these languages accumulate. I'm starting to look at C# the same way.
- rollcat 4y agoYou probably want a Lisp or a Forth instead then. Maybe (maybe!) Lua.