Ask HN: How do you mentally manage all the Ruby on Rails code?
I'm just starting to learn rails, and it seems that the mental load that comes from frequent context switch among files is enormous. Sometimes I forget what I was doing while I'm switching from one file to another. I know there are a lot of rails programmers on Hacker news, so wanted to ask:
Do you all have this problem? Or is this something that only newbies suffer from? Is there an effective design pattern that helps you code without confusion?
5 comments
[ 3.7 ms ] story [ 29.7 ms ] threadI didn't find your issue to be something that confused me. There seems to be a lot out there about fat models, skinny views/controller, but it sounds like you should really just ingrain MVC as it pertains to rails in your brain. Rails guides are your best friend here. MVC in effect is the effective design pattern your looking for.
My two cents from a fellow rails beginner. Oh, and check out my app at http://www.uhpartments.com
I may typically go from a cucumber feature, to step definitions, to the config/routes.rb file to a controller spec, then a controller, then a model spec, then a model, then a view, and cycle through that a few times. The cucumber features help to maintain the mental model of the highest level of what I'm doing then the lowest level might be the implementation of a method in the model.
Each step you're going from the business requirements end right through the full stack of the application until you're at the lowest level of logic. And what you should be focusing on is guided by failing tests and making them pass. E.g. to pass the feature you need a certain action for a controller which then needs a certain method on a model.
Whenever I write code I first of all put down all the logic in pseudocode in comments.
Then I write the actual code underneath the logic comments.
Works for me.
Coming to Ruby from scratch though, wow, I can imagine it being pretty intimidating. Having good tools (i.e. your editor) helps.