Re:Learning Ruby: Things I Like, Things I Miss from Python
by ysavir on Tuesday February 16, 2021 @02:23PM
(#26157694)
Very refreshing to see this take and I largely agree. People all too often refer to linters as The Rule rather than The Tool, and forget that a robot will never be able to evaluate the quality of a codebase. That requires human input (though Rubocop is very efficient for people that want to avoid human input--often the root cause of the problem).
That said, I am a fan of single-use private methods and think they have their place, with or without method-length rules.
Re:Learning Ruby: Things I Like, Things I Miss from Python
by andrewzah on Tuesday February 16, 2021 @09:27AM
(#26154118)
You can configure rubocop however you want.
If you find the defaults to be not good (which I agree), then simply update the rubocop.yml.
Re:Learning Ruby: Things I Like, Things I Miss from Python
by sodapopcan on Tuesday February 16, 2021 @11:24AM
(#26155475)
In fairness, ljm was responding to a comment that suggested following the style guide "to the dot".
Re:Learning Ruby: Things I Like, Things I Miss from Python
by ljm on Tuesday February 16, 2021 @05:16PM
(#26159450)
That was that's exactly the point I was aiming to address, thanks :)
Re:Learning Ruby: Things I Like, Things I Miss from Python
by sodapopcan on Tuesday February 16, 2021 @11:27AM
(#26155526)
Couldn't agree more. Our Rubocop is FULL of customizations and the odd override too (though there is a case some overrode a rule which caused massively confusing code).
"Single use private methods" is a little triggering to me... not even rubocop's fault. I've seen the likes of this before (single use):
def redirect_to_home_unless_user_present
redirect_to :home unless user.present?
end
Why!?? (that is a rhetorical "why")
Re:Learning Ruby: Things I Like, Things I Miss from Python
by ysavir on Tuesday February 16, 2021 @02:25PM
(#26157709)
That's a horrible usecase for single use private methods, agreed. But I think they're an excellent way to breakdown a complex chunk of code into smaller components, using the method names to describe what they're doing. That requires good naming, though; without good names, the effort is moot.
Re:Learning Ruby: Things I Like, Things I Miss from Python
by ljm on Tuesday February 16, 2021 @05:25PM
(#26159542)
I think they serve a good purpose once you realise you've stepped out of OOP. You have the idea of a command, or a service, and it does a bunch of procedural things as part of its execution. It only has one public method, so the private methods are a way to describe the steps of the command.
But that's an architectural decision, it's not code style. If rubocop tells you how to write a function then you're going to see nonsense like the example in our parent comment.
Re:Learning Ruby: Things I Like, Things I Miss from Python
by ysavir on Tuesday February 16, 2021 @05:49PM
(#26159784)
> I think they serve a good purpose once you realise you've stepped out of OOP. You have the idea of a command, or a service, and it does a bunch of procedural things as part of its execution. It only has one public method, so the private methods are a way to describe the steps of the command.
It doesn't have to be a step out of OOP, and their usage is not limited to "Single Public Method Objects". Single use methods are just a convenient and clean way to make complicated code easy to digest, OOP or not.
Default Rubocop is why you have codebases where code is still complicated, it's just hidden away inside single use modules (concerns) or inside single-use private methods. As far as I'm concerned you just can't defer the architecture of your codebase to a tool like that and I'm sure it teaches more bad habits than good ones.
Instead, decide these things for yourself and keep it in check during code review or the stage before that. Maybe even design rubocops of your own to help. The linter can still do a good job without telling you how to handle complexity.