A Writer's Ruby
world.hey.com
world.hey.com
and then the follow up blog post: "I DON'T KNOW WHY EVERYBODY IS MAD ABOUT THIS! I AM RIGHT!!!"
it's generally worth it, but it's still a kind of brain tax.
It is Friday and I'm tired, so maybe I need another re-read.
It’s also hyper strict, which is ok for a new project, but won’t play nicely with any legacy app.
Though I’m surprised DHH didn’t write his own RuboCop from scratch.
> That’s why we’re shipping a default linter, cleverly called RuboCop, in the next version of Rails. Not such that I, or anyone, can mandate what style your codebase ought to be written in, but such that you can find and enforce your own.
So every new Rails project has preset of linting style, which defaults to whatever the Rails team chose, but the point is that people are free to adjust the config file to whatever they prefer. So the same style is applied through the codebase.
His point is actually that linters lacking configuration are draconian.
> Some languages, like Go, have a built-in linter, which applies a universal style that’s been set by the language designers. That’s the most totalitarian approach.
I'd doubt it's the "built-in" aspect; it sounds quite a bit like it's the "universal style" that the author doesn't like.
This is from DHH, the Rails guy.
Maybe in the future we can just check-in the AST and a LLM will show us the code in whatever style it knows we like best.
It's a bit more than take-or-leave. Rubocop is configurable so individual projects could have their own style, no enforced style, or the default style.
And I don't like gofmt's output, personally, but I immediately saw the benefit to community-wide adoption specifically because of my experiences with Ruby and RoR and every project having it's own specific little (typically also totalitarian, very teapot dictator in my experience) set of StyleCop configurations. Frankly, there's a high level of bikeshedding that can open yourself up to with configurable linters that I'm too old to give a shit about.
edit/ I have no horse in this race, either... I use neither of these languages today professionally.
If you’ve coded as long as I have you’ll remember the endless bike shedding about style and random garbage that ended up in code bases. 2 spaces in a tab or 4? Who gives a shit.
My opinion is I don’t care what the style is so long as it’s consistent.
It's good to have Rubocop included by default, but I wonder how many teams are using the "omakase" Rails at this point? I don't think I've done a plain `rails new` at work in a decade.
I've heard these arguments a hundred times, and not once did I feel like the underlying sentiment was more than "I like/dislike X, therefor I want to limit how much other people can use X".
This is for the smallest possible style difference. I agree that a lot of folks get hung up on their personal preferences and want to fight about. Linters reduce those fights, and encourage everybody to just deal with it.
I like rubocop because it can be configured to be as flexible or strict as the team wants. Let the team establish what the level of consistency they want is.
def do_the_thing
return do_not_do_it unless first_conditional || second_conditional
okay_actually_do_it
endGlad that Rubocop is shipping with Rails though!
Yes, every `unless` could be rewritten with an `if` instead, certainly. But I like the implication of weight these keywords carry in English language. `unless` implies it's a minor condition, that the majority of runs should fall on the opposite side of the conditional, where as `if` does not -- both weights of the condition feel potentially equivilant-ish.
`unless admin?` is fine
`unless !admin?` is annoying `unless user.admin? && account.support?` leads to madness
I strongly agree with all of his descriptions of formatting and linting. I also strongly agree with him putting his personal style into Rubocop for the Rails codebase itself, and for project maintainers to be in control of what, if any, style they wish to enforce. But to omakase his style-guide into the consuming projects is surprising and against the very arguments against conforming to style-guides he presents in the first half of the post.
[1]: https://github.com/AuthorizeNet/sdk-ruby/commit/1972b153a893... [2]: https://github.com/maxim/narrative/blob/main/example_app/.ru...
Edit to add: I had experience years ago with RuboCop's auto correct making a breaking change, so I decided to distrust it. Be careful letting it change your source code.
https://www.amazon.com/Smalltalk-Style-Suzanne-Skublics/dp/0...
In the other hand, if the medium allows your own style, there is space created to become emotionally attached to unique coding styles.
As a preliminary conclusion, in this regard, would be to say, to what degree you value freedom of coder's expression versus commoditization of coder's work?
For libraries the answer is way less controversial. For your own apps in a tight group of very culturally aligned and productive Band of Brothers coders? Is not that clear.
Waiting on a traffic light the thinking is "if light is red/green, then wait/cross" its not like "don't cross unless its green".
Also if there is only one obvious way to do things it's a productivity boost! I cannot stress enough how many times we have debated coding styles, wasting precious development time! No customer cares of your coding style! If you are an engineering who cares more about the length of a line or the import order instead of a critical feature for the customer, you have to rethink the priorities.
Rubocop is a linter (etc) whose rule set can be easily customized and to include it in Rails wouldn't be possible without _some_ default set of rules. DHH addresses this apparent contradiction directly, too: "Not such that I, or anyone, can mandate what style your codebase ought to be written in, but such that you can find and enforce your own." I'm reading: A linter/formatter will be included in Rails 8 with a smart default rule set, and it can be easily customized. I don't see any contradiction.
I'm highly aligned with this decision as it could help alleviate a recurring pain point at our tiny company: managing code formatters and linters in our IDE (Solargraph, Rubocop, Ruby LSP, etc). Further, I'd expect excellent documentation on how we can customize the rules to best suit our purposes, too.
Formatters feel varying levels of painful on a per-language basis. The balance probably lies in empathy: It wasn't best to write it that way if it was not beneficial to either the machine or your collaborators.
On the other hand, if it brings someone joy to write in their distinct style, would we deny that joy?
It seems like that approach that would be fraught with errors considering how lenient gofmt can be at times but maybe it would be okay for simple stuff. e.g all of these ways of invoking methods:
fmt.
Println("Hello ",
"World",
)
fmt.Println("Hello ",
"World")
fmt.Println("Hello ", "World")The problem is that, as George Costanza said, we are living in a society. If you work on code that other people need to read and maintain, then there are a few individual concessions we should consider in order to benefit the larger group. In addition to linting, I'd also put types in this bucket. I don't think it's a coincidence that DHH doesn't like the way those feel, either.
They may cut into your personal enjoyment, but if it benefits the productivity of the larger group then that's a sacrifice you should probably consider. This is the entire reason that standards exist.
The right answer in my view is kind of what I think DHH is trying to get at: have enough rules to avoid straight up sloppiness and clear no-nos. Don't have any rules that might change based on human consideration.
How so?
Care to show examples? I haven’t encountered a single one where that would the case.
> Imagine every novel written in the same style, Hemingway indistinguishable from Dickens, Tolkien from Rowling. It would be awfully gray to enjoy the English language if there was only a single shade of prose.
Code is not a novel and your run off the mill developer is NOT Hemingway, Tolkien or Rowling. Code is a plumbing, nothing more, nothing less.
> we're shipping rubocop with the next rails
> choose one
I'm a pretty big DHH fanboy, but this article felt pretty odd in its tone and composure.
It reminds me of Newspeak, the new INGSOC language from Orwell’s 1984. »
I do not like something hence it’s totalitarian and newspeak.
Excellent material for some courses on discourse analysis!
It really is a non-event in most codebases I've worked with. Really happy that this exist and is a core aspect of the language now.
Personally, I haven't seen that failure mode, although I also haven't been in a situation where it'd come up.