2 ms·
I prefer Ruby's approach, which is not whitespace-sensitive, but has a very liberal approach to where expressions end. The general rule is, as with Python and
by lobster_johnson 14y ago
I prefer Ruby's approach, which is not whitespace-sensitive, but has a very liberal approach to where expressions end.
The general rule is, as with Python and Go, that open braces, brackets, parens or quotes have precedence; and operators or punctuation at the end of a line will continue to the next line.
In addition, there are some complicated parsing internals -- not just for expression-ending sensing, but also for supporting parens-less method calls -- that endow the parser with some compiler knowledge about what tokens are variables and what tokens are methods. In other words, the parser has information that violates the parser/compiler separation of concerns, but it works really well in practice.
The only time I ever use \ in Ruby is for string literals that need to be broken up for readability:
my_string = "This is a very long string that" \
" must be wrapped."
You can use + or <<, but this will be evaluated at runtime, whereas \ results in a single string allocation.
Of course, Ruby requires "end" for a lot of constructs, but it could have just as well have used braces.
- gnaritas 14y agoRuby can use braces instead of end, both are valid.
- lobster_johnson 14y agoHm? Only for blocks. Not classes, methods, if/unless, while or begin/rescue.
- gnaritas 14y agoDang, you're right, I could swear otherwise but yup, just on blocks.