Oh fun another style discussion! :-)<p>My own taste is for a "book style": write the code like you see in good books. I agree with most of this guide, although I'm pretty loose and case-by-case in practice. I've gradually added rubocop to lots of my projects, but then I wind up disabling tons of the rules.<p>I'm sad all the Ruby guides I've seen ban "and" and "or". I don't find them to be such an issue, and they are nicer to type & read. For one thing you can say `foo or raise "msg"` but need parens to say `foo || raise("msg")`. On team projects I sigh and go along with it, but it is a shame.<p>Speaking of "book style": I have a bunch of Python books with atrocious style, e.g. no spaces between operators or even between function arguments. How can anyone read that? I even see this from high-quality publishers like O'Reilly. What is going on with the Python world? Are their thumbs tired from all that indentation, so they leave out spaces everywhere else? ;-)<p>I really want to write a SQL style guide. There seems to be almost no consensus. My own formatting is idiosyncratic and not super principled, but I feel it is the most readable and expresses structure the best. It looks like this:<p><pre><code> SELECT a, b
FROM t1
LEFT OUTER JOIN t2
ON t2.t1_id = t1.id
WHERE t2.c = 'foo';
</code></pre>
(EDIT: Sorry, t2.c = 'foo' is a pretty dumb thing to do in an outer join. :-)<p>Other people like to do one or more of these things:<p><pre><code> SELECT a
, b
FROM t1
LEFT OUTER JOIN t2 ON t2.t1_id = t1.id
WHERE t2.c = 'foo';
</code></pre>
In other words:<p>- lead with the comma in SELECT.<p>- ragged left edge but line up all the single spaces in a column.<p>- indent the joins.<p>Anyway sorry for the rambling. :-) There is some observation that committees spend 90% of their time on trivial details and hardly discuss any of the important stuff, and style is no exception. But who doesn't like giving their opinion? :-)
The only thing I really don't like here is non indenting when inside case. I know that technically it's not a block, but in practice I find it much less readable
I made a comment on this thread[1] in 2014, and it was closed two days ago. I wondered why... guess this is why!<p>1: <a href="https://github.com/rubocop-hq/ruby-style-guide/issues/273" rel="nofollow">https://github.com/rubocop-hq/ruby-style-guide/issues/273</a>
I'll never understand Ruby's obsession with implicit return.<p>When reading code, my eye will immediately notice the `return` keyword and will have less to think about in terms of code execution.<p>The `return` keyword makes for great readability.
There's also StandardRB, it's like StandardJS but for ruby:<p><a href="https://github.com/testdouble/standard" rel="nofollow">https://github.com/testdouble/standard</a><p>Lightning talk about it here:<p><a href="https://www.youtube.com/watch?v=uLyV5hOqGQ8" rel="nofollow">https://www.youtube.com/watch?v=uLyV5hOqGQ8</a><p>Edit: I posted it on its own if you want to discuss:<p><a href="https://news.ycombinator.com/item?id=20186231" rel="nofollow">https://news.ycombinator.com/item?id=20186231</a>
Parens for method calls should only be used when things get ambiguous. Nothing bugs me more than seeing ruby code cluttered up with that garbage. I know, I know, but that's my personal bikeshed and I'll happily die on the roof of it.