Live data from Hacker News

Ruby adds experimental support for rightward assignments

blog.saeloun.com

11–20 of 172 posts

Re: Ruby adds experimental support for rightward assignments

#11
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…

Exactly how I feel. This is one of the reasons I'm not a huge fan of R, either

Re: Ruby adds experimental support for rightward assignments

#14
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.

Re: Ruby adds experimental support for rightward assignments

#15
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.

The fat rocket seems like an odd choice for an operator. It's already used for hashes - and you don't have to put set braces around hashes.

Re: Ruby adds experimental support for rightward assignments

#16
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…

If you visualize variables as "boxes" with values in them, "put 42 in age" makes sense.

Re: Ruby adds experimental support for rightward assignments

#18
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 ;)

Re: Ruby adds experimental support for rightward assignments

#20
post #12

Why? Why does ruby have an infinite amount of ways to do the same thing?

As someone else said in these comments, Ruby offers multiple ways to express things, so you have more options to "write how you think" as opposed to being pushed to "think how the language wants you to write".

I'm not saying it's good or bad, I'm just saying that appears to be one of the reasons for it.

Post reply on HN