News for hackers. Stuff that matters.
Re:Ruby adds experimental support for Rightward assignments by ericpauley on Thursday September 03, 2020 @10:24PM (#24371146)
To me this seems like a clear loss. The syntax is (as far as I can tell) strictly more verbose than the existing assignment syntax. Ruby is already plagued by a million-and-one ways to do everything, but at least in other cases simplicity (à la zen of Python) trades off for brevity.
Re:Ruby adds experimental support for Rightward assignments by drusepth on Friday September 04, 2020 @07:36PM (#24380021)
I don't particularly like the idea of rightward assignment (although the syntax itself seems fine to me), but the "million-and-one ways to do everything" is the biggest reason I strongly prefer the language over more "constrained/limited" languages like Python. In those terms, this seems like a definite win for the language (and those who choose to use it) for me.
Re:Ruby adds experimental support for Rightward assignments by dhagz on Friday September 04, 2020 @09:43AM (#24374834)
I don't even care about the verbosity - it's just ugly syntax. If I'm skimming a file that uses that syntax, I could easily get confused and think there's a comparison going on. One of Ruby's big draws (to me, at least) is code that is incredibly expressive and code that is aesthetically pleasing to look at. I feel this is serving the expressiveness at huge cost to aesthetics, and honestly there's not much gain to expressiveness in my opinion.

EDIT: I also completely forgot about the existing hashrocket syntax for maps.

Re:Ruby adds experimental support for Rightward assignments by baash05 on Saturday September 05, 2020 @07:55AM (#24382942)
+ 100
Re:Ruby adds experimental support for Rightward assignments by eejjjj82 on Friday September 04, 2020 @07:51AM (#24374097)
+100
Re:Ruby adds experimental support for Rightward assignments by adrianmonk on Thursday September 03, 2020 @09:14PM (#24370803)
Another language that supported this was Northern Telecom's PROTEL (https://en.wikipedia.org/wiki/Protel) from the 1980s.

The operator is written "->" and is informally called a "gazinta" ("goes into").

Re:Ruby adds experimental support for Rightward assignments by werdnapk on Thursday September 03, 2020 @09:20PM (#24370834)
A better example IMO is...

Before:

  result = case value
    when 5
      ...
    when 4
      ...
    end
After:

  case value
  when 5
    ...
  when 4
    ...
  end => result
The latter allows for some nicer formatting I think.
Re:Ruby adds experimental support for Rightward assignments by satisfaction on Thursday September 03, 2020 @10:46PM (#24371243)
At the expense of increasing the complexity to read code.
Re:Ruby adds experimental support for Rightward assignments by amw-zero on Thursday September 03, 2020 @11:09PM (#24371336)
How is the complexity increased?
Re:Ruby adds experimental support for Rightward assignments by eejjjj82 on Friday September 04, 2020 @07:52AM (#24374099)
Because now there are 2 ways to do the same thing with little obvious benefit other than syntactic bikeshedding.

2 ways to do something is more complex than 1.

But it's more than just the syntax of the code. It now means new lint rules, new coding standards in projects (some will allow => assignment, some will encourage conformity to legacy code, and others will disallow it entirely). There will be new Rubocop rules and other editor configs to update for proper syntax highlighting.

Syntactic changes like this with little obvious benefit need to be looked at skeptically. Just because something can be done, doesn't mean it should be.

Re:Ruby adds experimental support for Rightward assignments by mypalmike on Friday September 04, 2020 @12:38AM (#24371742)
Complexity increase from reading it has.
Re:Ruby adds experimental support for Rightward assignments by satisfaction on Saturday September 05, 2020 @11:20AM (#24384191)
Laughed at this I did.
Re:Ruby adds experimental support for Rightward assignments by sixstringtheory on Friday September 04, 2020 @03:31AM (#24372620)
As you read through code you can come across a huge switch and not know why until you look to the end. Now you’re reading bottom-up, which is just as unnatural as right-to-left for english speakers.

Not necessarily more complex, but not less complex either IMO. I often say complexity can’t be eliminated, only spread around differently; I think we’re seeing that here.

Re:Ruby adds experimental support for Rightward assignments by satisfaction on Saturday September 05, 2020 @12:50PM (#24384958)
I think it would be possible to think of this in terms of complexity theory, for N case statements to you would possibly have to check 2N locations for assignment. I wonder if you could do parallel assignment: var1 = case = var2
Re:Ruby adds experimental support for Rightward assignments by baash05 on Saturday September 05, 2020 @08:33AM (#24383079)
It's actually very simple to illustrate. Say this 5 => x in english. (three words or less)

Or this one

cat => person.pet

Re:Ruby adds experimental support for Rightward assignments by rubyn00bie on Friday September 04, 2020 @03:36AM (#24372638)
Does sort of make a hash in Ruby more confusing to the untrained eye (unless the hash rocket is totally dead, I haven't written Ruby since like the 2.3 days):

{ "age" => age, "name" => name }

I like the idea a lot. It'd probably allow for some nice functional looking code, but that's also the problem... it'd only look functional. And I think without VM/compiler/runtime support of functional programming it's pretty much a big waste of time.

I can use piece shit for a shoehorn; doesn't mean I should.

Re:Ruby adds experimental support for Rightward assignments by Tainnor on Friday September 04, 2020 @05:58AM (#24373469)
No, the hash rocket still exists. However, if you use symbols as keys, you can replace ":foo => bar" with "foo: bar". Many people, of course, use hashes with symbols as keys, but whenever you don't, you still need to use the hashrocket syntax.
Re:Ruby adds experimental support for Rightward assignments by netsectoday on Friday September 04, 2020 @12:56AM (#24371817)
Rightward assignment with a hash rocket?

I've been using ruby for a decade and I don't get why this is necessary (or even good).

Re:Ruby adds experimental support for Rightward assignments by jjgreen on Friday September 04, 2020 @10:31AM (#24375223)
Doesn't this introduce an ambiguity?

    def foo(*arg, **kwarg)
      puts "#{arg}/#{kwarg}"
    end
    b = 'meh'
    foo(:a => b)
Now this produces

    []/{:a=>"meh"}
But with right-assign

    [:a]/{}

?
Re:Ruby adds experimental support for Rightward assignments by baash05 on Saturday September 05, 2020 @07:53AM (#24382932)
Oh. The bugs that this would produce. And spotting it visually would be killer
Re:Ruby adds experimental support for Rightward assignments by mathw on Friday September 04, 2020 @03:46AM (#24372698)
I get why you'd want it, but I'm not sure they should be reusing => for it, since that already means something in Ruby.
Re:Ruby adds experimental support for Rightward assignments by arnvald on Friday September 04, 2020 @08:37AM (#24374369)
Yeah, I also start getting confused by reusing of the syntax. Now there's also a proposal to use { 1, 2, 3 } to represent sets - but {} is already used for blocks of code and for maps, so now that will be essentially a 3rd use case for curly braces.

On the other hand Ruby has already such a extensive syntax that it's hard to come up with something else that would not already be taken. -> represents lambda, >> is a valid method name, etc.

Re:Ruby adds experimental support for Rightward assignments by jaredcwhite on Friday September 04, 2020 @12:23AM (#24371690)
For simple one-line expressions, this doesn't seem to offer much. However, looking at multiline statements with FP-style or conditional logic, this can definitely improve the flow and visual rhythm of the code.
Re:Ruby adds experimental support for Rightward assignments by paozac on Friday September 04, 2020 @05:45AM (#24373392)
Could this be an initial step towards elixir-like chaining?

"foobar" => upcase() => x

Re:Ruby adds experimental support for Rightward assignments by scarmig on Friday September 04, 2020 @03:24PM (#24378080)
Why do most languages use right-to-left assignments? Is it purely a matter of path dependence? I guess also that binding a value to a name usually indicates that you'll use the name later on, and having the name on the LHS makes for a better UI for looking up the value the name is bound to.

On an unrelated side note, I've always thought "=" was a huge mistake in language design, confusing countless people who are coming into programming who reasonably mistake it for equality. I don't know why it won over ALGOL-style ":=".

Re:Ruby adds experimental support for Rightward assignments by dragonwriter on Friday September 04, 2020 @03:29PM (#24378129)
> On an unrelated side note, I've always thought "=" was a huge mistake in language design, confusing countless people who are coming into programming who reasonably mistake it for equality. I don't know why it won over ALGOL-style ":=".

Probably because adding a colon to an equality sign doesn’t clarify the meaning at all.

Had Algol (as some less widely influential for other reasons languages have) adopted something that more clearly represented movement into the variable being assigned like:

  a <- 25
Maybe it would have won out over “=" for assignment.
Re:Ruby adds experimental support for Rightward assignments by lioeters on Friday September 04, 2020 @03:59PM (#24378377)
I considered such an assignment operator for a little language I was developing, but there was an ambiguity between this:

  a <- 25
and this:

  a < -25
Since everything was an expression in the language, the latter would evaluate to a boolean. In the end I just went with "=" for assignment, and "==" for equality.
Re:Ruby adds experimental support for Rightward assignments by rowanG077 on Saturday September 05, 2020 @01:02PM (#24385048)
"=" is still equality. It's not an operator that compares two values. It's an operator that defines the left hand to be equal to the right hand. I feel like "=" for assignment is fine. For boolean comparison something like "=?" seems most clear, like asking a question whether the left and right hand side are equal.
Re:Ruby adds experimental support for Rightward assignments by scarmig on Saturday September 05, 2020 @04:43PM (#24386711)
In imperative languages, assignment has a side effect of making the LHS equal to the RHS. But it's still different from equality, since variables can be reassigned

E.g.

    a = 2
    a = 3
    2 = 3 //what???
Assignment is fundamentally part of the language execution model, which is entirely apart from anything related to mathematical equality. Even in languages where you can't rebind a variable name, it's still weird to use = as assignment, since it would have such different behavior than seemingly analogous operators like > and <.
Re:Ruby adds experimental support for Rightward assignments by baash05 on Saturday September 05, 2020 @05:27AM (#24382440)
This is so ugly. Already we have things like AND vs && or tailing if's that don't quite work like three line if's or how scoping do..end vs {} is ever so slightly different.

I'd wonder how the right assignment would work differently. What small gotcha would it create.

I also wonder how my co-workers would take it, if I started using it.. Or if I figured out how it was different and used it for the once case that it worked.

For me. having a million ways to do something leads to slower dev time. More context I'd need to load.

Re:Ruby adds experimental support for Rightward assignments by jbverschoor on Friday September 04, 2020 @02:17AM (#24372216)
I’d rather have changes to type safety, performance, or even a compiled binary. Or a merger between crystal and interpreted mode
Re:Ruby adds experimental support for Rightward assignments by lioeters on Friday September 04, 2020 @03:51PM (#24378327)
In a totally different context (but with same semantics), it's known as the ChucK operator, or "chucking".

https://chuck.cs.princeton.edu/doc/language/oper.html

Re:Ruby adds experimental support for Rightward assignments by syspec on Friday September 04, 2020 @10:51AM (#24375415)
Is there a place we can voice our concerns over this move.

I was just teaching Ruby to someone learning to code. I have to admit because all popular languages use leftward assignment it was one less thing to teach.

=> is pretty loaded as it is

Re:Ruby adds experimental support for Rightward assignments by baash05 on Saturday September 05, 2020 @07:51AM (#24382922)
Agreed. And it doesn't really improve anything. The argument that it makes code easier to read is bogus. Perhaps for people who only work in ruby. I suspect rubo-cop would have a rule against this a week after it was added.
Re:Ruby adds experimental support for Rightward assignments by nooyurrsdey on Saturday September 05, 2020 @01:57PM (#24385498)
why is this even needed? why introduce something to fix something that isn't a problem?
Re:Ruby adds experimental support for Rightward assignments by freen on Thursday September 03, 2020 @10:08PM (#24371067)
I’m a fan.

In my limited experience, leftward assignment breaks the “flow” explaining a program to a novice.

Re:Ruby adds experimental support for Rightward assignments by baash05 on Saturday September 05, 2020 @07:49AM (#24382911)
The problem is.. most popular languages use leftward assignment. Teaching a noob this would make other languages harder to read. I can switch from Java, to c++ to ruby.. My 9 year old figured out the leftward assignment. It feels like a change for change sake.