TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How do you mentally manage all the Ruby on Rails code?

6 pointsby kalistogaover 13 years ago
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:<p>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

sbauchover 13 years ago
I also started learning rails in August, just launched my first app. I skipped over TDD, planning on coming back and learning that. Testing just seemed too abstract when I set out, I found it easier to boot my app and "test" in the browser by seeing what changes I made in code actually did.<p>I 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.<p>My two cents from a fellow rails beginner. Oh, and check out my app at <a href="http://www.uhpartments.com" rel="nofollow">http://www.uhpartments.com</a>
sdfadfsover 13 years ago
Doing BDD/TDD along with a good text editor/IDE and learning the keyboard shortcuts will help. E.g. in vim with the Rails.vim plugin you can switch between controllers models and views very easily or go to the file inferred by what is under the cursor. You can also navigate back through your history too which can help.<p>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.<p>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.
onomojoover 13 years ago
Find a good team that'll let you work as an apprentice. You'll learn more in a month from a good team than you will in a year trying to go it alone. If you really want to do it yourself, the hardest part most new Rails devs face is building tests. If you focus on understanding how to build quality tests, the rest will just fall into place as you progress. The tests will help you keep your hands around the entire application as it grows in complexity and also help you build better code. Find some popular new open source Rails apps and sift through how they're handling routes. How do they organize their controller code? How do they build their models? Learning from someone else is always the best approach though. Find yourself a good team you can learn from and you'll save yourself a DIY headache.
azizaliover 13 years ago
I suffer the same problem if 1. I do not have proper comments 2. If I less variables. Its always good to use a ton of variables and minimum Constants. When initializing the variable put in comments what it is for.<p>Whenever I write code I first of all put down all the logic in pseudocode in comments.<p>Then I write the actual code underneath the logic comments.<p>Works for me.
petercooperover 13 years ago
Compared to a Java app, it's nothing, and a surprising number of Rubyists came from or at least <i>via</i> the Java world so don't really notice.<p>Coming to Ruby from scratch though, wow, I can imagine it being pretty intimidating. Having good tools (i.e. your editor) helps.