Live data from Hacker News

Ruby adds experimental support for rightward assignments

blog.saeloun.com

21–30 of 172 posts

Re: Ruby adds experimental support for rightward assignments

#23
post #7

> While the above pattern has become standardized, it feels somewhat unnatural as we read most of the spoken languages from left to right. Is this true (the 'unnatural' part)? Reading left to right, `age = 42` can be read as "age is 42" which feels perfectly natural in English. `42 => age` would be read as "assign 42 to age"? This feels more awkward to me. I'm not sure I understand why anyone would want Rightward ass…

A math tutor of mine was actually pretty angry at computer science for writing things like `a=1; a=2; //so 1=2 ?` I guess he'd rather have the "assign 42 to age"... Except he'd probably read `42 => age` as "42 implies age", which would probably cause him more sleepless nights ;)

He’d probably like a := 42 which is in a lot of languages actually! Also Erlang and other fp’s do consider = equivalence.

Re: Ruby adds experimental support for rightward assignments

#24
post #4

Rightward assignment is pretty strongly discouraged in the R community, due to the effect it has of burying the lede. That said, I always felt the same about Ruby’s inline if/unless (`puts "still working" unless done`) so maybe it will have a better reception in this community.

Interesting, that it became discouraged. Probably won’t make it into Ruby proper then. I don’t fault them for experiment.

Re: Ruby adds experimental support for rightward assignments

#25
post #7

> While the above pattern has become standardized, it feels somewhat unnatural as we read most of the spoken languages from left to right. Is this true (the 'unnatural' part)? Reading left to right, `age = 42` can be read as "age is 42" which feels perfectly natural in English. `42 => age` would be read as "assign 42 to age"? This feels more awkward to me. I'm not sure I understand why anyone would want Rightward ass…

[deleted]

Re: Ruby adds experimental support for rightward assignments

#26
I'm sorry but this "feature" is yet another design a hacker living in a bubble came up with. Most people think and program in English, or languages very close to English. In English I can read let x be 4ys and some change. I don't know how to read the arrow. 4ys and some change implies x? If this is a feature designed purely for speakers of SOV or OSV order languages like Japanese, that's fine, but the dominant language in technical discourse isn't one of those.

Re: Ruby adds experimental support for rightward assignments

#27
post #6

This hurts readability of code with lengthy expressions. Knowing the target of the assignment is usually more important than the particulars of the expression when you're skimming unfamiliar code. Having the variable pushed out to random locations on a ragged right side isn't helpful.

One of Ruby's philosophies is to provide multiple ways to express the same fundamental operation so that it can conform to your thoughts instead of forcing your thoughts to conform to it. You can still do it the old way where it makes sense. Whether this philosophy is helpful or harmful is another debate.

Until youre working on a team and your thoughts aren't the same as everyone else's thoughts.

Re: Ruby adds experimental support for rightward assignments

#28

To counter some of the complaints regarding readability, a major use case for this is simply hacking stuff together in the REPL. Sometimes you notice you want to have your result as a variable when you've just typed a line, and other solutions for this problem (Ctrl+A or ENTER plus foo = _) are not universal. Disclaimer: I'm not a core dev but saw a discussion amongst them about such use cases.

This is the exact reason I've wanted this, for a long time. I even asked Matz about it a conference once, probably 10-ish years ago.

Re: Ruby adds experimental support for rightward assignments

#29
post #7

> While the above pattern has become standardized, it feels somewhat unnatural as we read most of the spoken languages from left to right. Is this true (the 'unnatural' part)? Reading left to right, `age = 42` can be read as "age is 42" which feels perfectly natural in English. `42 => age` would be read as "assign 42 to age"? This feels more awkward to me. I'm not sure I understand why anyone would want Rightward ass…

A math tutor of mine was actually pretty angry at computer science for writing things like `a=1; a=2; //so 1=2 ?` I guess he'd rather have the "assign 42 to age"... Except he'd probably read `42 => age` as "42 implies age", which would probably cause him more sleepless nights ;)

I'm a big fan of immutability and using constantly so I agree with your tutor.

Re: Ruby adds experimental support for rightward assignments

#30
post #2

[question]: Is the main benefit of "Rightward assignments" readability and does this provide more benefits?

I think it would make sense for chained operations in a mental data flow sense.

    makejunk().filter().last(4) => fourthings
feels better than

    fourthings = makejunk().filter().last(4)
Post reply on HN