I love Ruby and its 10th ways of writing code to achieve same thing... Eh, there is a reason why Golang has such a huge popularity.
Ruby adds experimental support for rightward assignments
121–130 of 172 posts
Re: Ruby adds experimental support for rightward assignments
#122 $ awk 'BEGIN { "echo foo" | getline var; print var }'
fooRe: Ruby adds experimental support for rightward assignments
#123More unnecessary "features"...
Re: Ruby adds experimental support for rightward assignments
#124> 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…
Re: Ruby adds experimental support for rightward assignments
#125Earlier quoted context omitted.
A math tutor of mine was actually pretty angry at computer science for writing things like `a=1; a=2; //so 1=2 ?` I guess he'd rather have the "assign 42 to age"... Except he'd probably read `42 => age` as "42 implies age", which would probably cause him more sleepless nights ;)
> math tutor ... angry It's not the same language, so why should he expect the semantics to be the same?
It's a bit like discovering that inline C in your favourite non-C language isn't actually semantically correct C. If you're a mathematician, then you know, intimately and fluently, how math is spoken and written, so seeing something that looks exactly like "inline math", but isn't, is jarring.
(I don't get angry over it, but it is exactly counter to the extremely delicate and precise way mathematicians train ourselves to think about '='.)
Re: Ruby adds experimental support for rightward assignments
#126Earlier quoted context omitted.
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.
?- FOO = BAR, FOO = 1, print(BAR).
1Re: Ruby adds experimental support for rightward assignments
#127 DoThing()
.withSomeOtherThing()
.onSundays()
.withCharset(Blah.BLAH)
.betterAddThis(x -> { ret stuff() })
.build()
=> turducken
The whole assembly of the variable 'turducken' is drifting rightward. By the end we want to get to the point rather than backtrack.Re: Ruby adds experimental support for rightward assignments
#128>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.)
shrug I've used it. The overloading of the equals sign is something that has never made sense for assignment. (Seriously, it's hard to intentionally come up with dumber notation than x = x+1.) I do use -> sometimes. It's more natural to do the evaluation and then figure out where you're going to store the result (particularly when you're programming). This is minor as these things go. Definitely not a big deal one wa…
Re: Ruby adds experimental support for rightward assignments
#129This would be nice for situations where you have a lot of method calls daisy chained together. Like builders or Java Streams. DoThing() .withSomeOtherThing() .onSundays() .withCharset(Blah.BLAH) .betterAddThis(x -> { ret stuff() }) .build() => turducken The whole assembly of the variable 'turducken' is drifting rightward. By the end we want to get to the point rather than backtrack.
DoThing()
.withSomeOtherThing()
.onSundays()
.withCharset(Blah.BLAH)
.betterAddThis(x -> { ret stuff() })
.build()
.into(turducken)
Where a.into(b) is really (into a b), which is a macro sugar for (set b a) and not a function.