3 ms·
I'm always astonished by Python. For ages "dataclasses" have been called struct or record in other languages and are fast first class values. In Python, they i
by lprthx 4y ago
I'm always astonished by Python. For ages "dataclasses" have been called struct or record in other languages and are fast first class values.
In Python, they invent a weird, slow concept and discuss it for a decade, probably while writing 10 PEPs in the process. Through conferences, Stackoverflow, etc. people are slowly convinced that the concept is natural.
- empthought 4y agoPython has had named tuples since 2008 and slots for attributes since 1999, both of which are fast first class values. I’m always astonished by ignorant people feigning knowledge of their areas of ignorance.
- mejutoco 4y agoIt is the same concept. In rust structs are defined with the struct keyword, and can have methods. And there is no class keyword for classes. In haskell, structs are defined with the keyword data. Maybe that is where the inspiration comes from. https://lotz84.github.io/haskellbyexample/ex/structs https://lotz84.github.io/haskellbyexample/ex/structs In any case, it seems each language chooses equally confusing keywords. Syntax is not a big deal IMO if the concept is clear.
- eru 4y ago> In haskell, structs are defined with the keyword data. Maybe that is where the inspiration comes from. In Haskell, Rust and Python you can also just have tuples, if you want to. In Haskell you can use `newtype` or `type` to name your tuples and use them as records. Of course, as you say, you can also use the `data` keyword in Haskell. Or you can use church encoding to use functions as records.. Lots of (confusing) possibilities.
- dec0dedab0de 4y agothis reminds me of a Perl guy once asking me why Python calls hashes dicts. I said that a dict is a key value object with a defined set of included methods. The fact that it uses a hash under the hood is just an implementation detail. If a better technique comes along, Python is free to change it. Also If someone wanted to do something crazy like make an implementation of python where every dict was a nosql database, that would be fine as long as it implemented the same behavior. For structs you have to remember that in python everything is reference passed, so some of the differences between structs and classes that you see in other languages do not apply. But I suspect the real practical reason is that python already has structs, which are used for interoperability with C structs. Or any structured binary format really.