There was one thing with block chaining that I was really hoping they'd hit on. They didn't. They had: # good names.select { |name| name.start_with?("S") }.map { |name| name.upcase } I've noticed that sort of chaining is changing towards: names.select { |name| name.start_with?("S") } .map { |name| name.upcase } Which can be further chained (if need be) like so: names.select { |name| name.start_with?("S") } .map { |na…
Github Ruby Styleguide
41–50 of 73 posts
Re: Github Ruby Styleguide
#42Now-a-days we have computers which can show more than 80 characters at a time. "Keep lines fewer than 80 characters", Is this recommendation still valid?
Of course we do. We also have serial ports that go way faster than 9600, so at last "ed" can be used to its full potential.
Re: Github Ruby Styleguide
#43I can't stress enough how important it is to _not_ use `and` and `or`. As a former die-hard fan of those operators, it bit me in the ass so hard when those didn't exactly work the way they were supposed to. I've been using && and || now for years and I haven't looked back. /PSA
I agree. But in all code that I write, regardless of pretty much whatever language it's written in, I always explicitly add parentheses around what I want the order of operations to be. "1 * 3 + 4 / 20 && foo" is unreadable. No one wants to memorize the order of operations for every language they use and have to figure it out in their head. Make life easier for the people who have to maintain that line of code you ju…
Re: Github Ruby Styleguide
#44Now-a-days we have computers which can show more than 80 characters at a time. "Keep lines fewer than 80 characters", Is this recommendation still valid?
In principle, having a line width limit is a worthwhile idea. 120 rarely gives me problems, and I can fit 240 characters wide in any case.
Re: Github Ruby Styleguide
#45Re: Github Ruby Styleguide
#46There was one thing with block chaining that I was really hoping they'd hit on. They didn't. They had: # good names.select { |name| name.start_with?("S") }.map { |name| name.upcase } I've noticed that sort of chaining is changing towards: names.select { |name| name.start_with?("S") } .map { |name| name.upcase } Which can be further chained (if need be) like so: names.select { |name| name.start_with?("S") } .map { |na…
Re: Github Ruby Styleguide
#47I can't stress enough how important it is to _not_ use `and` and `or`. As a former die-hard fan of those operators, it bit me in the ass so hard when those didn't exactly work the way they were supposed to. I've been using && and || now for years and I haven't looked back. /PSA
I agree. But in all code that I write, regardless of pretty much whatever language it's written in, I always explicitly add parentheses around what I want the order of operations to be. "1 * 3 + 4 / 20 && foo" is unreadable. No one wants to memorize the order of operations for every language they use and have to figure it out in their head. Make life easier for the people who have to maintain that line of code you ju…
Maybe I'll eat my foot some day, but
(a == 1) && (b == 2)
or (2 * 3) + 1
is nothing but code smell to me.Re: Github Ruby Styleguide
#48Re: Github Ruby Styleguide
#49What's worse, Ruby give the "correct" relative precedence to &&/||. I suspect this inconsistency is the reason the OP cautions against using and/or*. It's too bad because I miss the low precedence and/or operators (from perl) that can be used to avoid parenthesis that &&/|| would require in the presence of assignment, etc.
Re: Github Ruby Styleguide
#50 %w(word1 word2 word3)
with %w[word1 word2 word3]
both result in ["word1", "word2", "word3"]
I prefer the bracket delimiters since they better indicate the array nature than the parens. In % notation you can choose your own delimiters, so why not use brackets?