4 ms·
See https://bugs.ruby-lang.org/issues/16122 https://bugs.ruby-lang.org/issues/16122 for lengthy deliberation of the justification (in particular, of the relativ
by inopinatus 4y ago
See https://bugs.ruby-lang.org/issues/16122 https://bugs.ruby-lang.org/issues/16122 for lengthy deliberation of the justification (in particular, of the relative utility vs merely enhancing Struct), and discussion of the naming options, but let's crucially note that Data itself is not an immutable struct, it is a factory for classes when the instances of those classes are intended to be immutable structs.
Hence
Product = Data.define(:name, :price)
creates a Product class, most likely during initialisation; then in application code we could subsequently write
cheese = Product.new("Wensleydale 200g", 499)
and here it's cheese that is immutable; the point being, we're still naming our domain objects purposefully.
In that light, I think it's appropriate for a language to use generic terms for fundamental elements. For example, almost everything is descended from Object and we're fine with it.
- otikik 4y agoThank you for the link and the explanation. I still think Data should not have been used