Live data from Hacker News

Ruby adds experimental support for rightward assignments

blog.saeloun.com

51–60 of 172 posts

Re: Ruby adds experimental support for rightward assignments

#51
>R language also has a similar way of doing this 42 -> age.

Ah yes, the R language, a model of clarity, beauty and lightness in the world of programming languages. Truly an example to follow.

(And it's not like anyone ever uses that "feature" in the R world either.)

Re: Ruby adds experimental support for rightward assignments

#53
post #39
post #30

Earlier quoted context omitted.

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

I’m not sure. In shell, I think

  makejunk | grep foo | tail -4 > fourthings
is more popular than

  > fourthings makejunk | grep foo | tail -4
Having said that, I don’t understand why you would add this, but then, I don’t understand the popularity of ruby or other languages that think adding alternative ways to do things most of the time is a good thing.

Re: Ruby adds experimental support for rightward assignments

#54
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 works well for some cases. You end up with

return if a.nil? return if attempts In this case "return if" becomes like a keyword and you can ignore it and focus on the rest of the expression. It also seems very readable for other simple values like `return false if ...`. But I agree, as soon as the code to the left of the `if` gets non-trivial it is harder to read.

Re: Ruby adds experimental support for rightward assignments

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

It seems the opinionated, directive "there's only one way to do it" approach is winning over the hacking around, "wrapping around your mind" approach. Lisp and Perl have had their times under the sun, now it's all about Python and Go. Perhaps these things are cyclical.

Re: Ruby adds experimental support for rightward assignments

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

Python has the same "rightward conditional" thing.

Any time I use it, I wish python had just gone with the normal ternary (? :) operator.

Re: Ruby adds experimental support for rightward assignments

#58
Ruby's parser is notoriously complex; if I remember correctly, only a few members of the core team even know how to maintain it without introducing regressions.

The craziest part of this is that Ruby does not provide a full featured Ruby parser, so its entire static and dynamic analysis ecosystem depends on a (actually very high quality) 3rd party parser, begrudgingly maintained by someone who (AFAIK) doesn't even write Ruby anymore: https://github.com/whitequark/parser

When I see new language features like this, I think of how Ruby's entire tooling ecosystem depends on the dramatically underfunded (and therefore primarily goodwill) efforts of high output maintainers like whitequark and a few others. Ruby's highly dynamic and untyped nature means these tools are all the non-runtime guarantees you can get, basically. Epitome of digital infrastructure.

Consider asking your company to fund some of these people:

* https://github.com/whitequark (maintains parser)

* https://github.com/sponsors/bbatsov (maintains RuboCop)

* https://github.com/sponsors/mbj (maintains unparser and mutant)

---

As context, I know this stuff intimately because I used to contribute heavily to most static and dynamic analysis tools in the Ruby ecosystem (https://github.com/backus?tab=overview&from=2017-12-01&to=20...) and used to track new ruby changes really closely: https://cognitohq.com/new-features-in-ruby-2-4/

Re: Ruby adds experimental support for rightward assignments

#59
post #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”?)

I read assignment like "age gets 42".

Re: Ruby adds experimental support for rightward assignments

#60
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 doesn't sound any more difficult to resolve than the fact that you are probably working on a team where different individuals prefer different programming languages.
Post reply on HN