Ruby adds experimental support for Rightward assignments
blog.saeloun.com
Ruby adds experimental support for Rightward assignments
1–10 of 39 posts
Re: Ruby adds experimental support for Rightward assignments
#2Another language that supported this was Northern Telecom's PROTEL (https://en.wikipedia.org/wiki/Protel) from the 1980s.
The operator is written "->" and is informally called a "gazinta" ("goes into").
Re: Ruby adds experimental support for Rightward assignments
#3A better example IMO is...
Before:
result = case value
when 5
...
when 4
...
end
After: case value
when 5
...
when 4
...
end => result
The latter allows for some nicer formatting I think.Re: Ruby adds experimental support for Rightward assignments
#4I’m a fan.
In my limited experience, leftward assignment breaks the “flow” explaining a program to a novice.
Re: Ruby adds experimental support for Rightward assignments
#5To me this seems like a clear loss. The syntax is (as far as I can tell) strictly more verbose than the existing assignment syntax. Ruby is already plagued by a million-and-one ways to do everything, but at least in other cases simplicity (à la zen of Python) trades off for brevity.
Re: Ruby adds experimental support for Rightward assignments
#6I’m a fan. In my limited experience, leftward assignment breaks the “flow” explaining a program to a novice.
[deleted]
Re: Ruby adds experimental support for Rightward assignments
#7A better example IMO is... Before: result = case value when 5 ... when 4 ... end After: case value when 5 ... when 4 ... end => result The latter allows for some nicer formatting I think.
At the expense of increasing the complexity to read code.
Re: Ruby adds experimental support for Rightward assignments
#8Re: Ruby adds experimental support for Rightward assignments
#9For simple one-line expressions, this doesn't seem to offer much. However, looking at multiline statements with FP-style or conditional logic, this can definitely improve the flow and visual rhythm of the code.