TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ruby adds experimental support for Rightward assignments

34 pointsby matagusover 4 years ago

16 comments

ericpauleyover 4 years ago
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.
评论 #24380021 未加载
评论 #24374834 未加载
评论 #24382942 未加载
评论 #24374097 未加载
adrianmonkover 4 years ago
Another language that supported this was Northern Telecom&#x27;s PROTEL (<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Protel" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Protel</a>) from the 1980s.<p>The operator is written &quot;-&gt;&quot; and is informally called a &quot;gazinta&quot; (&quot;goes into&quot;).
werdnapkover 4 years ago
A better example IMO is...<p>Before:<p><pre><code> result = case value when 5 ... when 4 ... end </code></pre> After:<p><pre><code> case value when 5 ... when 4 ... end =&gt; result </code></pre> The latter allows for some nicer formatting I think.
评论 #24371243 未加载
rubyn00bieover 4 years ago
Does sort of make a hash in Ruby more confusing to the untrained eye (unless the hash rocket is totally dead, I haven&#x27;t written Ruby since like the 2.3 days):<p>{ &quot;age&quot; =&gt; age, &quot;name&quot; =&gt; name }<p>I like the <i>idea</i> a lot. It&#x27;d probably allow for some nice functional <i>looking</i> code, but that&#x27;s also the problem... it&#x27;d only <i>look</i> functional. And I think without VM&#x2F;compiler&#x2F;runtime support of functional programming it&#x27;s pretty much a big waste of time.<p>I can use piece shit for a shoehorn; doesn&#x27;t mean I should.
评论 #24373469 未加载
netsectodayover 4 years ago
Rightward assignment with a hash rocket?<p>I&#x27;ve been using ruby for a decade and I don&#x27;t get why this is necessary (or even good).
jjgreenover 4 years ago
Doesn&#x27;t this introduce an ambiguity?<p><pre><code> def foo(*arg, **kwarg) puts &quot;#{arg}&#x2F;#{kwarg}&quot; end b = &#x27;meh&#x27; foo(:a =&gt; b) </code></pre> Now this produces<p><pre><code> []&#x2F;{:a=&gt;&quot;meh&quot;} </code></pre> But with right-assign<p><pre><code> [:a]&#x2F;{} ?</code></pre>
评论 #24382932 未加载
mathwover 4 years ago
I get why you&#x27;d want it, but I&#x27;m not sure they should be reusing =&gt; for it, since that already means something in Ruby.
评论 #24374369 未加载
jaredcwhiteover 4 years ago
For simple one-line expressions, this doesn&#x27;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.
paozacover 4 years ago
Could this be an initial step towards elixir-like chaining?<p>&quot;foobar&quot; =&gt; upcase() =&gt; x
scarmigover 4 years ago
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&#x27;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.<p>On an unrelated side note, I&#x27;ve always thought &quot;=&quot; was a huge mistake in language design, confusing countless people who are coming into programming who reasonably mistake it for equality. I don&#x27;t know why it won over ALGOL-style &quot;:=&quot;.
评论 #24378129 未加载
评论 #24385048 未加载
baash05over 4 years ago
This is so ugly. Already we have things like AND vs &amp;&amp; or tailing if&#x27;s that don&#x27;t quite work like three line if&#x27;s or how scoping do..end vs {} is ever so slightly different.<p>I&#x27;d wonder how the right assignment would work differently. What small gotcha would it create.<p>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.<p>For me. having a million ways to do something leads to slower dev time. More context I&#x27;d need to load.
jbverschoorover 4 years ago
I’d rather have changes to type safety, performance, or even a compiled binary. Or a merger between crystal and interpreted mode
lioetersover 4 years ago
In a totally different context (but with same semantics), it&#x27;s known as the ChucK operator, or &quot;chucking&quot;.<p><a href="https:&#x2F;&#x2F;chuck.cs.princeton.edu&#x2F;doc&#x2F;language&#x2F;oper.html" rel="nofollow">https:&#x2F;&#x2F;chuck.cs.princeton.edu&#x2F;doc&#x2F;language&#x2F;oper.html</a>
syspecover 4 years ago
Is there a place we can voice our concerns over this move.<p>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.<p>=&gt; is pretty loaded as it is
评论 #24382922 未加载
nooyurrsdeyover 4 years ago
why is this even needed? why introduce something to fix something that isn&#x27;t a problem?
freenover 4 years ago
I’m a fan.<p>In my limited experience, leftward assignment breaks the “flow” explaining a program to a novice.
评论 #24371195 未加载
评论 #24382911 未加载