See related discussion here: https://github.com/crystal-lang/crystal/pull/4592
This is in the context of "list of expressions" (if that's its correct name) e.g. (a; b; c)
, (a)
, ()
.
List of expressions is currently universal (can have any number of expressions). This "removal" is actually adding a special case that a list of 0 expressions is invalid.
This can also adversely affect generated code
My opinion is:
(foo; bar; ...)
are allowed, empty expression ()
is allowed too. Because I think this is natural enough behavior and make sense.So I have a question to @asterite. You said:
So
(1; 2)
is allowed,(1)
is allowed, but () shouldn't parse. I added that at one point because Ruby does that, but I don't think it makes much sense. Not even for code generation.
Why do you think ()
doesn't make sense? For example empty blocks like begin; end
and def foo; end
return nil
. Especially return
without a value returns nil
, it is really useful. I believe, in Crystal empty means nil
anytime, don't you?
Thanks everyone for the comments. We discussed this further with @asterite and @bcardiff, and agree that it is not a good idea to do this, basically for the reasons mentioned by @oprypin and @MakeNowJust.
So now that we're keeping this, we'll reopen and merge the PR to fix the formatter.
Most helpful comment
Thanks everyone for the comments. We discussed this further with @asterite and @bcardiff, and agree that it is not a good idea to do this, basically for the reasons mentioned by @oprypin and @MakeNowJust.
So now that we're keeping this, we'll reopen and merge the PR to fix the formatter.