Live data from Hacker News

Ruby adds experimental support for rightward assignments

blog.saeloun.com

111–120 of 172 posts

Re: Ruby adds experimental support for rightward assignments

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

That's why tcl uses:

set age 42

Re: Ruby adds experimental support for rightward assignments

#112
post #26

I'm sorry but this "feature" is yet another design a hacker living in a bubble came up with. Most people think and program in English, or languages very close to English. In English I can read let x be 4ys and some change. I don't know how to read the arrow. 4ys and some change implies x? If this is a feature designed purely for speakers of SOV or OSV order languages like Japanese, that's fine, but the dominant langu…

Comprehension follows perception

Re: Ruby adds experimental support for rightward assignments

#113

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

It will share with you its wisdom (the last line is printed by the interpreter):

  ?- FOO = 1,
  BAR = 2,
  FOO = BAR.
  false.

Re: Ruby adds experimental support for rightward assignments

#114
post #95
post #8

Earlier quoted context omitted.

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

Where these conversations tend to break down is "you are using it wrong", which is technically correct but practically is a non sequitur.

I can't control other people. Neither can you. Unfortunately saying that and acting like it's true are two separate things, and so we are chronically making decisions based on an illusion of control that is unhealthy to the point of self-harm. It just sets you up for disappointment and/or antisocial behavior (eg delusions of grandeur)

We put safeties on missiles. We color code and cover emergency power cutoffs in server rooms. We've started putting finger preservation devices on table saws. But code? Well it's your fault for backing into the shutoff button.

"You're using it wrong" = "People will use it wrong." = "You're going to have to work with people who use it wrong" = "You are going to run out of places to hide their bodies and just have to accept it being used wrong."

The question isn't "can it be used right?". Every bad library ever written has been "used right" by at least the author, even if not all the time. The question is "can we live with how often it is going to be used wrong?"

Re: Ruby adds experimental support for rightward assignments

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

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.

There almost invariably is a subtle difference (very commonly, in precedence), and that's usually a key part of the motivation for the (near) synonym.

Re: Ruby adds experimental support for rightward assignments

#116
post #72

Uh.. I'm not sure I like this, in a language that already has a similar boolean operator (although I suppose that goes for all uses of such "arrow" operators). But still: a = 2 b = 1 b >= a # false b >= a => a # assign false to a? b => a # assign 1 to a?

It already has at least two different uses for the exact sigil "=>" (hash construction, identifying capture variable in a rescue clauses), which is probably more significant than that it has a kinda similar sigil used as a comparison operator.

Like natural language (but unlike programming languages constructed with thought toward ease of automated parsing), Ruby syntax is quite context sensitive.

Re: Ruby adds experimental support for rightward assignments

#117
post #26

I'm sorry but this "feature" is yet another design a hacker living in a bubble came up with. Most people think and program in English, or languages very close to English. In English I can read let x be 4ys and some change. I don't know how to read the arrow. 4ys and some change implies x? If this is a feature designed purely for speakers of SOV or OSV order languages like Japanese, that's fine, but the dominant langu…

> I don't know how to read the arrow.

As a description (which is an easier translation of this idiom into English than an imperative) “is assigned to”.

Imperatively, English tends to prefer verb-object with implicit subject, so we ought to be using a Lisp family language (setq “foo” 42) maps better to English imperative structure than most popular languages that do imperative assignment.

Re: Ruby adds experimental support for rightward assignments

#118
post #91
post #70

Earlier quoted context omitted.

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

So?

Why does this need to be in the language when both major REPLs already support it? Why must this be yet another alternative way to accomplish the same thing as the way that’s existed since the first days of the language?

There is no argument in favor of this addition. It doesn’t allow anything new, it provides a pointless alternative to the current way of doing things, and the one situation where it’s useful—REPLs—there’s already a feature that renders it completely unnecessary.

Re: Ruby adds experimental support for rightward assignments

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

"age is 42" may be a statement while "is age 42" may produce a boolean.

And I don't see why a statement can't describe a mutation.

Re: Ruby adds experimental support for rightward assignments

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

I read it as "42 is stored in age". The works particularly well for a long chain of methods that should end in storing the resulting value in a variable. I know this might seem to be the most conventional way that Ruby is written; it makes a single statement take 8 lines instead of 1, it transforms a value over the course of the statement instead of sending messages to tell an object to transform itself, and it ignor…

... and it's useful how? It obscures the assignment at the end of an arbitrarily long statement instead of giving the value a name right up front.

It feels a bit like a new method definition syntax that allows you to put the name after the `end` for... reasons.

Post reply on HN