I don’t hate the idea. I feel like namedtuple works well enough. Maybe better effort could be making namedtuple behave more like a struct? Or some new type like frozennamedtuple?
I’m not a fan of introducing yet another “type of class”.
In my humble opinion, if we do introduce rust-like match it should work on top of the existing concepts of dataclass, namedtuples, and union-types to avoid confusion on when to use which mechanism.
Also, type hints aren’t compulsory, but they are so damn useful that I’d be okay if some features only worked when the original variables had type hints.
Opinion: This doesn't really solve a problem like dataclasses v. namedtuples did. This mostly boils down to someone not really liking the dataclass syntax and deciding that adding yet another way to write classes is the way to go and is somehow more teachable (because now we need to teach both).
Maybe it'd be nicer in a few use cases, but I don't really feel it's worth the expansion to the syntax burden.
I agree with the article that dataclasses and namedtuples aren't as good as they can be. But I think the solution should be to make dataclasses native, and not namedtuples.
So we could write something like:
dataclass Point:
x: int @"why not also add new syntax for documentation?"
y: int @"the size of translation on the Y axis"
def methods_as_usual(self):
...
I wouldnt hate its existence, and certainly i would always prefer anyone use this over namedtuple.
At the same time, i think i would never use it. 90% of my classes these days are dataclasses, and the set that don’t inherit from anything, and have no methods are vanishingly small
I don’t know that harkening to rust structs makes much sense in python, (…which can have methods)
Python
Welcome to the Python community on the programming.dev Lemmy instance!
📅 Events
Past
November 2023
- PyCon Ireland 2023, 11-12th
- PyData Tel Aviv 2023 14th
October 2023
- PyConES Canarias 2023, 6-8th
- DjangoCon US 2023, 16-20th (!django 💬)
July 2023
- PyDelhi Meetup, 2nd
- PyCon Israel, 4-5th
- DFW Pythoneers, 6th
- Django Girls Abraka, 6-7th
- SciPy 2023 10-16th, Austin
- IndyPy, 11th
- Leipzig Python User Group, 11th
- Austin Python, 12th
- EuroPython 2023, 17-23rd
- Austin Python: Evening of Coding, 18th
- PyHEP.dev 2023 - "Python in HEP" Developer's Workshop, 25th
August 2023
- PyLadies Dublin, 15th
- EuroSciPy 2023, 14-18th
September 2023
- PyData Amsterdam, 14-16th
- PyCon UK, 22nd - 25th
🐍 Python project:
- Python
- Documentation
- News & Blog
- Python Planet blog aggregator
💓 Python Community:
- #python IRC for general questions
- #python-dev IRC for CPython developers
- PySlackers Slack channel
- Python Discord server
- Python Weekly newsletters
- Mailing lists
- Forum
✨ Python Ecosystem:
🌌 Fediverse
Communities
- #python on Mastodon
- c/django on programming.dev
- c/pythorhead on lemmy.dbzer0.com
Projects
- Pythörhead: a Python library for interacting with Lemmy
- Plemmy: a Python package for accessing the Lemmy API
- pylemmy pylemmy enables simple access to Lemmy's API with Python
- mastodon.py, a Python wrapper for the Mastodon API