Crystal: Remove `()` from the language

Created on 22 Jun 2017  路  3Comments  路  Source: crystal-lang/crystal

help-wanted feature compiler

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.

All 3 comments

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:

  • When multiple expressions (foo; bar; ...) are allowed, empty expression () is allowed too. Because I think this is natural enough behavior and make sense.
  • When empty expression is disallowed, multiple expressions are disallowed too. Because multiple expressions have no use case in fact and this change breaks naturalness of list of expressions.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

straight-shoota picture straight-shoota  路  91Comments

MakeNowJust picture MakeNowJust  路  64Comments

farleyknight picture farleyknight  路  64Comments

asterite picture asterite  路  78Comments

xtagon picture xtagon  路  132Comments