Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They’re both shortcuts to creating class-like things.

Take @dataclass in python for example, that’s similar to Struct for Ruby.

‘Data’ documentation from the GitHub PR (https://zverok.space/ruby-rdoc/Data.html):

    Data provides no member writers, or enumerators: it is meant to be a storage for immutable atomic values. But note that if some of data members is of a mutable class, Data does no additional immutability enforcement

    See also Struct, which is a similar concept, but has more container-alike API, allowing to change contents of the object and enumerate it.


> Take @dataclass in python for example, that’s similar to Struct for Ruby.

From a cursory look data classes seem to do a lot more than structs. Structs seem like a mutable version of namedtuples, or js objects, down to behaving like a collection / iterable.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: