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.)
51–60 of 172 posts
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.)
Earlier quoted context omitted.
I think it would make sense for chained operations in a mental data flow sense. makejunk().filter().last(4) => fourthings feels better than fourthings = makejunk().filter().last(4)
Not to me, and other people who use Ruby sparingly
makejunk | grep foo | tail -4 > fourthings
is more popular than > fourthings makejunk | grep foo | tail -4
Having said that, I don’t understand why you would add this, but then, I don’t understand the popularity of ruby or other languages that think adding alternative ways to do things most of the time is a good thing.Earlier quoted context omitted.
Ruby currently supports "Rightward conditionals": user.delete() if deleteUser It is probably thought that this feature would result in similar readability improvements.
I don't find that more readable at all. I prefer: if deleteUser user.delete() end It's easier for me to read. It doesn't try to hide away logic. And if the line gets longer if the conditional gets more complex or I want to add an else I can without reformatting.
return if a.nil? return if attempts In this case "return if" becomes like a keyword and you can ignore it and focus on the rest of the expression. It also seems very readable for other simple values like `return false if ...`. But I agree, as soon as the code to the left of the `if` gets non-trivial it is harder to read.
Why? Why does ruby have an infinite amount of ways to do the same thing?
As someone else said in these comments, Ruby offers multiple ways to express things, so you have more options to "write how you think" as opposed to being pushed to "think how the language wants you to write". I'm not saying it's good or bad, I'm just saying that appears to be one of the reasons for it.
[question]: Is the main benefit of "Rightward assignments" readability and does this provide more benefits?
Ruby currently supports "Rightward conditionals": user.delete() if deleteUser It is probably thought that this feature would result in similar readability improvements.
Any time I use it, I wish python had just gone with the normal ternary (? :) operator.
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 write Ruby anymore: https://github.com/whitequark/parser
When I see new language features like this, I think of how Ruby's entire tooling ecosystem depends on the dramatically underfunded (and therefore primarily goodwill) efforts of high output maintainers like whitequark and a few others. Ruby's highly dynamic and untyped nature means these tools are all the non-runtime guarantees you can get, basically. Epitome of digital infrastructure.
Consider asking your company to fund some of these people:
* https://github.com/whitequark (maintains parser)
* https://github.com/sponsors/bbatsov (maintains RuboCop)
* https://github.com/sponsors/mbj (maintains unparser and mutant)
---
As context, I know this stuff intimately because I used to contribute heavily to most static and dynamic analysis tools in the Ruby ecosystem (https://github.com/backus?tab=overview&from=2017-12-01&to=20...) and used to track new ruby changes really closely: https://cognitohq.com/new-features-in-ruby-2-4/
> 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”?)
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.
Until youre working on a team and your thoughts aren't the same as everyone else's thoughts.