3 ms·
1. About Verbosity: that's not common nor idiomatic ruby. You'd much more often see a case statement there, and nowadays with pattern matching. It look like idi
by chucke 2y ago
1. About Verbosity: that's not common nor idiomatic ruby. You'd much more often see a case statement there, and nowadays with pattern matching. It look like idiomatic python though...
2. About Long Expressions to Detect nil: rails devs have had Object#try fir many ears to avoid that, and &. syntax since ruby 2.3 (10 years?).
3. About Overuse of self, again, clearly the author hasn't done enough python... and that's hardly common, given the many options ruby gives you (ivar access, self-less implicit method calls...)
4. About Collecting Results in Temporary Variables, ruby has supported map/filter/reduce for more than 15 years. This was however quite common code to find years ago from ex-java devs...
5. About Sorting and Filtering in Memory, that's actually the only legitimate problem I can think of. However, I'd hardly consider that Ruby's fault, and more of a superpower of composition of abstractions (datasets to enumerables) which should obviously be handled with care (and perhaps linked against? Does ruboxop support smth of the kind?)
Actual thing I see many times and should be avoided: construction an hash of options first, then pass it as kwargs:
opts = {
foo: 1,
bar: 2
}
meth(opts)
- kunley 2y agoYeah, agreed; this whole article seems like good-hearted, but still from kind of a novice in Ruby: part of it is wrong and part is obvious
- quesera 2y agoI agree -- the article recommendations are generally subjective/oversimplified. Except for point 5, which is a almost always a mistake of using the "tool at hand" (Ruby), and not knowing when to switch to a more appropriate layer (Active Record or SQL). But what's wrong with an instantiated hash as kwargs? :)
- chucke 2y agoIt isn't a big win compared to just calling the method with it: meth(foo: 1, bar: 2) # even if multiline meth( foo: 1, bar: 2 ) while needlessly allocating an hash (kwargs optimize that).
- quesera 2y agoFor this small example, I certainly agree. But I like to use a prepared hash when there's preparation that must be done, or if it just makes the data more clear.