Re:Ruby 3.4, No More TypeError with **Nil as It Is Treated a...
by xutopia on Monday May 13, 2024 @02:38PM
(#40346693)
Ruby is such a malleable language that its syntactic use cases are still being figured out and refined today. I'm loving this language every new iteration I see. A pleasure to use as my go to language.
Re:Ruby 3.4, No More TypeError with **Nil as It Is Treated a...
by pzmarzly on Monday May 13, 2024 @03:02PM
(#40346970)
Interestingly, JavaScript has the opposite problem: {...null} is fine (returns {}), but [...null] is not (TypeError: Spread syntax requires ...iterable not be null or undefined).
Re:Ruby 3.4, No More TypeError with **Nil as It Is Treated a...
by kevincox on Tuesday May 14, 2024 @09:09AM
(#40354852)
This tricks me all of the time. Part of me wants for it to work to avoid allocating an empty array object in situations like `[...opts?.foo.map(format)]`. On the other hand I appreciate the stricter type safety.
Re:Ruby 3.4, No More TypeError with **Nil as It Is Treated a...
by gleenn on Monday May 13, 2024 @02:55PM
(#40346880)
This sounds like it might cause bugs but seems like a good idea in general. Clojure treats nil the same way where "assoc"ing to it turns it into a hashmap and "cons"ing it turns it i to a list. Nil as basically the "empty data structure of undefined type" is actually quite useful in a lot of contexts to make coding simpler and not have to special case the base case in an if-statement every time.
Re:Ruby 3.4, No More TypeError with **Nil as It Is Treated a...
by barkbyte on Monday May 13, 2024 @03:03PM
(#40346986)
I think changing the behaviour of nil in general for an existing language with tons of code already in the world would be beyond insane, on the verge of willfully destructive. Fortunately, that’s not what as happening here. This only applies in the case of using nil as a splat, which is narrow enough that I think it’s probably safe and it’s a sensible default behaviour.
Re:Ruby 3.4, No More TypeError with **Nil as It Is Treated a...
by lcnPylGDnU4H9OF on Monday May 13, 2024 @05:54PM
(#40348951)
I'm not sure what currently working code would be broken by this. If anything, it seems like it would just obviate workarounds.
Though, now that I'm thinking about it, I have written and read absolute monstrosities. This could break something somewhere but I'm confident it would land squarely in the realm of "well yeah, but don't do that".
Re:Ruby 3.4, No More TypeError with **Nil as It Is Treated a...
by kazinator on Tuesday May 14, 2024 @02:29AM
(#40352230)
If you make something work which previously threw an error, it affects programs in which that error happens but is handled (whether by fluke or design).
One obvious example is a regression test case which confirms that the error is generated; that test now fails and must be removed.
It could sneak into an application.
They are just willing to crack those eggs to make their omelette.
Re:Ruby 3.4, No More TypeError with **Nil as It Is Treated a...
by Alifatisk on Monday May 13, 2024 @06:56PM
(#40349541)
I don’t know how to feel about this, when I get this error then I know I haven’t thought about a certain case that could happen and I should handle it.
Though, now that I'm thinking about it, I have written and read absolute monstrosities. This could break something somewhere but I'm confident it would land squarely in the realm of "well yeah, but don't do that".
One obvious example is a regression test case which confirms that the error is generated; that test now fails and must be removed.
It could sneak into an application.
They are just willing to crack those eggs to make their omelette.