mampf
mampf copied to clipboard
Architectural resources to "tame" the codebase
This is a "structured dumping ground" for useful resources that could help refactoring our code base. I think some issues are pretty-well summarized by a teaser for Jason Swett's book "Growing Large Rails Applications".
"How did our Rails app get to be such a confusing mess?"
Your models are bloated When you open up a model file, you see a grab bag of random stuff. There are five methods that relate to this concept, two methods that relate to that concept, and about 20 one-off methods that don't have anything to do with anything else. The problem is especially bad in one or two "god objects" that you can't seem to figure out any way to break up.
Your controllers are confusing Your controllers are bloated, but in a different way. By necessity, you've added custom methods to some of your controllers beyond the defaults that Rails gives you. In some cases you've added quite a lot of custom methods. You want to practice "fat models, skinny controllers" but somehow the controllers are still left carrying a lot of weight.
Your views are messy You know that view code should be kept as simple as possible. Yet there's still some code that doesn't seem to fit comfortably in the view layer, nor the controller model layers, nor anywhere else. You've tried using helpers, and that helps some, but it also creates a mess of its own.
Your app generally lacks structure Your Rails app feels like an amorphous blob, a heap of parts. You easily can't find what you want when you want to find it. When you add new code, it's unclear where to put it, so you just add it to one of the growing piles that are lying everywhere. Your team has tried to fix the problem by adding an app/services directory, and that helps a little, but mostly it just moves the mess around.
While it might not be that bad, we currently tend towards that direction with ever-growing models that act more like a dumping ground. Let's tackle this issue. It's a big one of course and will probably need a lot of time to solve, if it's ever to be solved. It's rather a continuous improvement I guess.
I don't think there's this one recipe that you follow to achieve a super clean and understandable codebase. See also Rails can only take you so far. Apps are too different and operate in various domains that they need different "solutions". Instead, let's collect many resources here to learn about new design patterns and experience from other people that deal with big code bases. I don't think buying Jason's book is necessary (it is not that cheap in the end) and am certain that we can gather a good pool of websites, blog posts etc. to move forward.
Feel free to edit my comments down below to add links you find useful.