crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.5k stars 1.62k forks source link

Exception handling syntax is not Ruby compliant #1732

Closed pierrelegall closed 9 years ago

pierrelegall commented 9 years ago

The Crystal rescue syntax is not Ruby compliant. With exception handling, Crystal failed to run Ruby code, and vice versa.

In Crystal, it looks like :

rescue e : TypeOfException

But in Ruby, we can see :

rescue TypeOfExcepion => e

I think it is weird to choose not to follow the Ruby syntax on this kind of detail. Would someone kindly put me in the picture ?

Seriously, this is not about the best syntax, I just complain about this unexpected incompatibility.

asterite commented 9 years ago
  1. Crystal is not a Ruby implementation, there are many syntax differences
  2. => is used in Ruby for hash literal. In crystal we use : for type restrictions, so we think : is more consistent. We think => in exception syntax in Ruby is inconsistent.
pierrelegall commented 9 years ago

I understand the compiled program problematics. Crystal cannot handle the dynamical properties of a Ruby VM. Moreover, Crystal typing syntax is needed and Ruby interpreters yell on parsing. However, it is thinkable to have compatible parsers in both world. Rubies could update their parser to ignore typing syntax (Python 3.5 seems to behave like this).

We don't have the option to write Ruby-Crystal friendly code today (this is the case for exceptions handling). I just notice that some maybe justified but avoidable things don't follow the way to make it possible.

asterite commented 9 years ago

I'll close this because it's starting to look like a duplicate of https://github.com/manastech/crystal/issues/593

We have no plans of changing Crystal's syntax to make it Ruby compatible.