

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

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?
======
sbauch
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.

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.

My two cents from a fellow rails beginner. Oh, and check out my app at
<http://www.uhpartments.com>

------
sdfadfs
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.

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.

------
onomojo
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.

------
azizali
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.

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.

------
petercooper
Compared to a Java app, it's nothing, and a surprising number of Rubyists came
from or at least _via_ the Java world so don't really notice.

Coming to Ruby from scratch though, wow, I can imagine it being pretty
intimidating. Having good tools (i.e. your editor) helps.

