-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Ary Borenszweig edited this page Aug 5, 2015
·
17 revisions
Apart from the "Crystal has Ruby-inspired syntax" reason, there are more reasons:
- If you copy and paste a snippet of code, you have to manually re-indent the code for it to work. This slows you down if you just wanted to do a quick test.
- If you want to comment some code, for example comment an
ifcondition, you have to re-indent its body. Later you want to uncomment theifand you'll need to re-indent the body. This slows you down and it's cumbersome. - Macros become harder to write. Consider the json_mapping macro. It defines
defs, usescase ... when ... else ... endwithout having to bother whether the generated code will be indented. Withoutend, the user would have to correctly indent the lines that would be generated. - If you want a template language like ERB or ECR for a language that doesn't care about whitespace, you'll have to put those
endto signal where conditions/loops/blocks end. - Right now you can do:
[1, 2, 3].select { |x| x.even? }.map { |x| x.to_s }. Or you can do it withdo .. end. How would you chain calls in an indentation-based language? Usage of{ ... }is not valid, only indentation should be used to match code blocks. - Assuming one day we have a REPL, in which you tend to write code quickly, it's tedious and bug-prone to match indentation, because whitespace is basically invisible.
Because of all the above reasons, know that the end keyword is here forever: there's no point in trying to suggest changing the language to an indentation-based one.
Before suggesting syntax additions, ask this question:
- Can it be currently done with the current syntax?
If the answer is "yes", there's probably no need to add new syntax for something that can be already done. Adding syntax means we have to be sure it doesn't conflict with the existing syntax. all users will have to learn something new, and it needs to be documented.
Maybe the current syntax is long to write or involves a couple of composed methods, but we should favor method composition instead of specific rules for specific problems.