Live data from Hacker News

Ruby adds experimental support for rightward assignments

blog.saeloun.com

91–100 of 172 posts

Re: Ruby adds experimental support for rightward assignments

#91
post #70
post #28

Earlier quoted context omitted.

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.

This is a completely unnecessary feature. `_` is always assigned to the value of the previous expression. >> 4 + 2 => 6 >> _ => 6 >> "abc" + "def" => "abcdef" >> _ => "abcdef Adding this kind of syntax for something that's already trivial to do is honestly kind of distressing for me as a Ruby developer who's been around since early 1.8. I still strongly believe that the `key: value` hash syntax was a massive mistake.…

`_` being assigned the result of the last statement evaluated is an IRB feature [1], not a ruby feature - hence the note that it is not a universal solution.

[1]: https://github.com/ruby/irb/blob/master/lib/irb/context.rb#L...

Re: Ruby adds experimental support for rightward assignments

#93

The right way to do this is the way Prolog does it. It doesn't matter if you say VAR = 12 or 12 = VAR or 1,2,10 = A, B, C It does whatever it takes to make the left and the right sides equivalent to each other.

That is interesting. How does it work when a variable is on each side?

foo = 1

bar = 2

foo = bar

Re: Ruby adds experimental support for rightward assignments

#95
post #8

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.

Is this like 'unless'? Unless is great if it's the first or second clause on the line. If it's the tenth, then it feels more like slapstick and I am the butt of the joke. Haha, just kidding, we aren't really going to call that function. Similarly, rightward: someBigFunction(thatNeedsAnswersFrom(), otherFunctions(), true) => variableIAmDebugging Three unnamed Laws of Computing that everyone ignores and at their peril:…

If your 10th clause is an unless then you're using it wrong. I agree that unless and the right hand assignment can be used incorrectly but that's not a reason to omit the feature :)

Re: Ruby adds experimental support for rightward assignments

#96

>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.)

If you're interactively exploring data using the REPL it can be quite handy.

You do have the correct sentiment in that for actual code meant to be distributed to other human beings it's almost never a good idea to use it although I've seen use cases, particularly involving Tidyverse constructs, where it arguably makes sense.

Re: Ruby adds experimental support for rightward assignments

#97
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]

Re: Ruby adds experimental support for rightward assignments

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

Python has the same "rightward conditional" thing. Any time I use it, I wish python had just gone with the normal ternary (? :) operator.

> Python has the same "rightward conditional" thing.

No, python writes the ternary operator with words, it doesn't have rightward conditionals.

The key difference is that the else clause is required in the Python ternary, where it's optional in a conditional.

Re: Ruby adds experimental support for rightward assignments

#99

Earlier quoted context omitted.

Alright, I did in fact chuckle, out loud. But I gotta ask: does it have the correct precedence? And sure, throwing some superficial math at the problem works. But is that a coincidence? I guess what I'm asking is: how does Nim know that `=>` is infix? How does it derive the correct precedence? It looks like spooky magic, but Nim is pretty well-designed in my experience: what's going on here?

> how does Nim know that `=>` is infix? I expect it's the ` Haskell works the same way.

Ah, and templates are a rewrite engine on the AST! That completely slipped my mind.

So the compiler itself just sees the `a = b`, the `b => a` is never visible, therefore precedence isn't germane to the template itself.

Neat.

Re: Ruby adds experimental support for rightward assignments

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

If everyone thought like this there would only be one language that everyone used. Writing software is creative.
Post reply on HN