Live data from Hacker News

Ruby adds experimental support for rightward assignments

blog.saeloun.com

41–50 of 172 posts

Re: Ruby adds experimental support for rightward assignments

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

> math tutor ... angry

It's not the same language, so why should he expect the semantics to be the same?

Re: Ruby adds experimental support for rightward assignments

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

that's why having a coding style guide is important and to lint it every commit.

Re: Ruby adds experimental support for rightward assignments

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

That’s rubocop’s raison d’etre. I like that you can be completely free exploring with code in the style you like, and “button up” when it needs to become shipping/shared code.

Re: Ruby adds experimental support for rightward assignments

#44
post #33
post #5

Earlier quoted context omitted.

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.

It's subjective, the point is that some people prefer it.

Re: Ruby adds experimental support for rightward assignments

#45
post #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.

The example given in comment #20 provides a practical reason for it, in that in some cases it makes things more consistent visually. But mostly these reasons are subjective and some people will be more or less sensitive to them. A lot of programming language design and tool design in general is not completely rational or about functionality only.

Re: Ruby adds experimental support for rightward assignments

#46

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.

I've got " q = " in muscle memory by now. I feel like I've got a hand tied behind my back when I'm in a place that doesn't support those keybindings, but I'm not sure finding rightward assigns peppered at the 128th stack depth is going to make me a happier developer.

Re: Ruby adds experimental support for rightward assignments

#47
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 is the age

Re: Ruby adds experimental support for rightward assignments

#48
post #2

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

I think I would use this if I were writing a cpu emulator in Ruby (which I wouldn't). It mirrors assembly, but I'm not sure that's a good thing.

Re: Ruby adds experimental support for rightward assignments

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

But “age is 42” is a statement/Boolean, not a mutation. “Let age be 42” is more natural, but doesn’t sound well on reassignments (“let age now be 42”?)
Post reply on HN