Live data from Hacker News

Ruby adds experimental support for rightward assignments

blog.saeloun.com

31–40 of 172 posts

Re: Ruby adds experimental support for rightward assignments

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

synonyms in ruby seem to be a mistake. Searching code for certain usage patterns ends up needing more complicated regular expressions taking into account all synonym variations.

If you've seen a method one way many times while learning, then see a synonym, you end up having to search up docs to make sure there isn't some subtle difference.

Re: Ruby adds experimental support for rightward assignments

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

`42 => age` would probably be "42 is age", or if it was `42 => person.age` you'd read it "42 is person's age".

Re: Ruby adds experimental support for rightward assignments

#33
post #5
post #2

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

Ruby currently supports "Rightward conditionals": user.delete() if deleteUser It is probably thought that this feature would result in similar readability improvements.

I don't find that more readable at all. I prefer:

    if deleteUser
      user.delete()
    end
It's easier for me to read. It doesn't try to hide away logic. And if the line gets longer if the conditional gets more complex or I want to add an else I can without reformatting.

Re: Ruby adds experimental support for rightward assignments

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

This is actually one of the things I first liked about Ruby. Then it became one of the main reasons I started disliking Ruby.

Re: Ruby adds experimental support for rightward assignments

#35
post #27
post #6

Earlier quoted context omitted.

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.

Sure. Peer review, making sure that the code one person has written makes sense to the rest of the team, is a fundamental and incredibly important part of pretty much all team-based development projects.

Re: Ruby adds experimental support for rightward assignments

#36

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.

Then maybe it should be a feature that only exists in the REPL like _.

Re: Ruby adds experimental support for rightward assignments

#37

Here is a feature ticket. The usage in a data transformation pipeline feels right and appropriate as in comment #20 https://bugs.ruby-lang.org/issues/15921

I don't find that reason any more compelling than any other reason I've read. I still don't get why it's better than what already exists.

Re: Ruby adds experimental support for rightward assignments

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

Agreed, when I read that line I found myself saying it out loud wondering if it was a typo.

`favorite_color = red' == "Favorite Color is Red"

Which feels more natural than: "Red is Favorite Color"

Re: Ruby adds experimental support for rightward assignments

#39
post #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)

Not to me, and other people who use Ruby sparingly

Re: Ruby adds experimental support for rightward assignments

#40
post #27
post #6

Earlier quoted context omitted.

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.

[deleted]
Post reply on HN