Re:Ruby adds a new core Data class to represent immutable va...
by djur on Tuesday November 29, 2022 @10:12PM
(#33796557)
Yeah, I'm happy to see this. Every Ruby shop I've worked for has some kind of hand-rolled immutable struct, possibly in addition to various implementations provided by libraries. The backwards compatibility reasoning for not adding an immutable flag to Struct (my first instinct) makes sense. Struct has always been kind of wonky anyway. Getting both positional and kwargs for free is great. I also appreciate that they kept the implementation minimal for now. The pull request shows a very elegant way of implementing default arguments using only language features, which is a good sign:
[ Parent
| on HN ]
Re:Ruby adds a new core Data class to represent immutable va...
by bigtunacan on Tuesday November 29, 2022 @10:56PM
(#33796854)
The libraries that provide immutability often provide stronger enforcement than this new Data class. I like the idea of something like this as part of Ruby core, but this was a chance to do it right and I don't think they took it far enough.
Re:Ruby adds a new core Data class to represent immutable va...
by djur on Wednesday November 30, 2022 @12:12AM
(#33797228)
You're thinking deep immutability? I'm not sure that's ever going to make sense to bundle with the language. Too many caveats.
I'd rather see incremental additions to this minimal Data API than trying to do too much at once. Lots of love for the Ruby dev team but they don't always have the clearest idea of what problems their users are trying to solve.
Re:Ruby adds a new core Data class to represent immutable va...
by bigtunacan on Wednesday November 30, 2022 @10:35AM
(#33802132)
Yes, that's exactly what I was thinking. The problem is that without deep immutability this is still open to abuse/miss-use. When I'm creating an immutable struct I'm trying to prevent future developers from accidental mistakes.
Re:Ruby adds a new core Data class to represent immutable va...
by sacnoradhq on Wednesday November 30, 2022 @02:56AM
(#33798109)
Reinventing the wheel is cancer to support. There's already Concurrent::ImmutableStruct.