3 ms·
highly recommend clicking the "witness the inevitable future" button as a python oldie coming back into python, i've been surprised by dataclasses. are they ba
by swyx 3y ago
highly recommend clicking the "witness the inevitable future" button
as a python oldie coming back into python, i've been surprised by dataclasses. are they basically "backwards compatible better classes"? any strong blogposts or readings that people can share about better typed python/OSS module publishing practices?
- deleted 3y ago[deleted]
- dcastm 3y agoIt’s under Growth > Files for those struggling to find the button
- kzrdude 3y agoDataclasses are orthogonal to typing (IMO), they just use types for their evocative syntax for fields. Dataclasses are nice - they are a pared down version of the attrs library, so a simple way to create data-only or mainly-data records through classes. They are not intended to replace all classes.
- fbdab103 3y agoYou reminded me of this article[0] where the author asks why not dataclasses by default? I am inclined to agree, dataclasses feel Pythonic in that they remove boilerplate with reasonable defaults (sorting, hashing, etc). [0] https://blog.glyph.im/2023/02/data-classification.html https://blog.glyph.im/2023/02/data-classification.html
- acbart 3y agoYes, I really wish this was the reality. I would even be very happy with a new `data` keyword for this purpose. I'm teaching `dataclasses` in my CS1, and it's nice, but frustrating that A) students have to remember the import, and B) all my slides always have to be a bit longer thanks to the `@dataclass` line taking up space. This is a real problem for some of my longer examples...
- swyx 3y agowelllll i'm not seriously proposing this but if you had a new extension, like .ty or .datapy or something, you could put whatever syntax you wanted in there and compile it down to .py...
- plonk 3y agoYes please keep stacking compilers on top of compilers. I loved dealing with Qt builds in CMake. Can't wait for Python's stable and consistent packaging tools to handle not-Python code that compiles down to Python code.
- xigoi 3y agoYou may be interested in http://coconut-lang.org/ http://coconut-lang.org/
- wiml 3y agoDataclasses are basically just better namedtuples. They do work nicely with type-annotations, but the two features are kind orthogonal.