Live data from Hacker News

Ruby adds experimental support for rightward assignments

blog.saeloun.com

101–110 of 172 posts

Re: Ruby adds experimental support for rightward assignments

#102

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

I don't understand what point you are trying to make here. Do you not like the feature simply because R has a similar feature? Why not look at examples given here and by others and decide/comment on whether it adds clarity or expressiveness or not?

I am making two points:

-Arguing that adding a feature is ok because "R does it" is comically wrong when one is acquainted with all of R's warts and superfluous stuff

-Not even the R world uses that feature either, so we have actual empirical evidence that it's not that helpful to developers.

Re: Ruby adds experimental support for rightward assignments

#104
post #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 wr…

`parser` is indeed a fantastic gem. @whitequark is the initial author but today it is maintained by @iliabylich

Re: Ruby adds experimental support for rightward assignments

#105
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 ignores the concept of encapsulation by moving the interesting actions into the foreground rather than being hidden within an object.

Below is an _incredibly_ contrived example. Take note how the `=> final_value` syntax is useful. The alternative is to place a `final_value = ` at the _top_ of the statement. I'll admit: placing the assignment at the top of the method chain helps point out to the reader of the code that an assignment is happening. However, more useful I think is quickly recognizing the flow of data.

  "hello"
    .chars
    .size
    .*(10980643.4)
    .to_i
    .to_s(36)
    .upcase
    => final_value
  
  puts(final_value)
  # => WORLD

Re: Ruby adds experimental support for rightward assignments

#106

Earlier quoted context omitted.

I don't understand what point you are trying to make here. Do you not like the feature simply because R has a similar feature? Why not look at examples given here and by others and decide/comment on whether it adds clarity or expressiveness or not?

I am making two points: -Arguing that adding a feature is ok because "R does it" is comically wrong when one is acquainted with all of R's warts and superfluous stuff -Not even the R world uses that feature either, so we have actual empirical evidence that it's not that helpful to developers.

I wouldn't say an additional notes section at the end of article showing that is syntax is not unprecedented is an argument that the feature is ok because R does it. The author is simply giving additional context to allow readers to form their own opinion.

It's fine to not like the feature–I don't know enough about its usecase to feel one way of another–but your comment felt unnecessarily negative without adding much to the discussion.

Knowing that R users have access to these syntax and choose not to use it is interesting to consider, but that was overshadowed by your first statement.

Re: Ruby adds experimental support for rightward assignments

#107

Earlier quoted context omitted.

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

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

Not quite. Imagine you have:

  3 + b => a
Is that 3 + a = b, or a = 3 + b? Precedence still comes into it. (I don't know nim's solution.)

Re: Ruby adds experimental support for rightward assignments

#108

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

I don't understand what point you are trying to make here. Do you not like the feature simply because R has a similar feature? Why not look at examples given here and by others and decide/comment on whether it adds clarity or expressiveness or not?

R is a very...haphazard language. Not to say it isn't elegant in places, but I wouldn't describe it as a consistent, well planned language. I suspect it's not the rightward assignment OP has an issue with, but the fact that they're looking at R as an example to follow.

Re: Ruby adds experimental support for rightward assignments

#109
post #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 wr…

Is Ripper dead? I attempted to do some minor work on Ripper and it was profoundly painful. My explanation for Ripper boiled down to a domain specific language in parse.y comments that gets translated into C via a very confusing Ruby script, which manually calls Ruby VM functions, that wait for it, are dynamically defined. This constructs a parse tree. If Ripper is still getting maintained, I'm seriously impressed.

Re: Ruby adds experimental support for rightward assignments

#110
post #73

This is true to Ruby's Perl heritage. There is more than one way to do everything, even the most basic of operations. Quiz: what does the following Ruby code do? a = b => c = d

Makes me reject the PR for lack of clarifying parentheses.

Do you really punish everybody else because you can't remember precedence rules?
Post reply on HN