I propose to use ++ to connect two or multiple statements, e.g.
do_this ++ do_that ++ do_something
It is equivalent to (do_this; do_that; do_something) but more readable.
It can be used to replace below idiom
do_something and return if condition
with
do_something ++ return if condition
The current way is very error prone because do_something might return false/nil in some cases and cause problems. And new Ruby programmers might not understand the meaning behind this idiom and mimic it blindly.
I noticed someone proposed 'then' for same purpose (See http://bugs.ruby-lang.org/issues/6201) but is postponed to 3.0 because it is already a keyword. I like 'then' too but if it is not acceptable due to backward compatibility issue, then '++' is a good alternative.
This seems like a workaround to me. But one that I don't like because Ruby will have to keep supporting this even if/after 'then' is accepted.
The problem is that while I find "then" readable to me, I don't think '++' is obvious to someone reading such statements. Specially when i++ has already a very known behavior in most other languages...
Sorry I didn't know this. I have never seen ++ in ruby code (except probably in books) and that made me think it is not valid syntax. Wonder what is the usefulness of '1 + +1' though.
He didn't say it was useful. He just stated that the argument for allowing it in Ruby 2.0 is not valid because it would also break compatibility just like 'then'. Also, he is advicing you to suggest new syntax to 'then' in that other ticket instead of creating new ones.
By the way, it works in Ruby because the parser will read "a ++ 2" the same way as "a++2", "a + +2" or "a + + 2". Ruby allows one to specify a number with its signal like "-3" or "+5", so "+" is not the plus operator in those representations. It doesn't mean someone actually write "+2" in real code...
If 'then' or '++' does not work, what about 'also'? I'm not a native English speaker and not sure whether it sounds natural. Maybe someone can come up with something that fits well to this case.
do_this also do_that also return if condition
Yusuke, feel free to close this ticket if you prefer and we can continue our discussion in the other one.
Even though using 'also' means adding a new keyword and breaks compatibility, practically no one uses it as method name or variable name. I searched my whole ruby lib directory, it never appeared in code.
Another candidate is \. It doesn't break compatibility and matches the use of \ in current syntax.
Since we use \ to concatenate parts to a statement, \ can be used to concatenate statements to a statement group, assuming (a; b) is called a statement group. E.g.
Guoliang, my issue with "(a; return b) if condition?" is that I don't find it readable and would prefer to read "a then b if condition?" instead. But I don't think that "a \ return if condition?" is more readable than the currently allowed approach. In fact I prefer the current one to "\" which is very unintuitive.
This is not a matter of just finding some operator that wouldn't break backward compatibilities. This is about readability.
You are right, anything other than 'then' or maybe 'also' hurts readability. Guess I'm too obsessed with finding something that can work for this case :-P