The more Ruby I write, the more readable my Ruby becomes. Odd, but the secret seems to be to do nothing the way the Rubyists In Crowd does things. Here's a useful function:
def concat( *args )
ret = ''
for a in args do ret += ( a.to_s() ) end
return ret
end
Four-space indentation is more readable. The for ... in ...
loop is more readable than the each
iterator. Putting parentheses after function and method calls improves readability. Always using a return
statement to return values is another. Rejecting the whole Tim-Toady-loving basket of string notations in favor of just concatenating with the "+" operator is more readable.
The Rubyists In Crowd will never think my code is cool. But Monty, my pet python who's looking over my shoulder as I write this, just said, "Martin, that's almost Pythonic."
"Monty, please turn away for a moment. You'll puke over all my papers if you see what I'm about to write."
Here's the official, Rubyists-approved-but-don't-show-Monty version of that function:
def concat(*args)
ret = ''
args.each {|a| ret += a.to_s}
ret
end
I'm a big believer in conventions, but I've never seen a language where the conventions always favor the less-readable form. Never.
Or maybe I'm unaware of the deeper secrets of Ruby. Certainly the Rubyists In Crowd knows a lot more about Ruby than I do.