2012-10-27

Welcome to the Real World

A couple of weeks ago I've started working on a pretty big Rails app. After dealing with my lightweight pet projects, a few inconveniences occurred. If you're lazy, just jump to the end to see the summary of the important things I've learned.

App, Y U No start?

An empty rails app starts in 1-2 seconds. My biggest pet project starts in 5 seconds. The big app starts in 25 seconds. That's a guaranteed 25 second overhead for every operation that has to load Rails - console, runner, tests, server. Multiply this overhead by number of times you do those during the day and it can easily build up into a solid amount of time wasted.

Testing woes

All tests run a solid half-hour, and you only see failures in the end. Continuous integration server helps, but at least in the very beginning I'd rather make sure everything works on my machine before pushing my commits to origin.

An when you run tests one by one, you get to wait those extra 25 seconds every time. That can give you cancer.

The Tricky Extras

There is a small zoo of additional stuff that has to be installed and running for the main app to work. That stuff may also run in several instances, one for each environment you want to use (development, test). And when you suddenly realize that something required is not running, you waste more precious time to find what's wrong and to fox it. Basically it's a never ending fight with the environment, until you gradually get used to it and everything starts to work, because just like an experienced puppet master you have an eye for things and grow to feel what strings should be pulled to get back on track.

And of course, those extra dependencies have their own rituals, like you occasionally may have to rebuild the indexes for the full text search server.

The Code Base

Navigating around a huge codebase of a heavily dynamic language is quite tricky, especially in the very beginning.

This is mostly it. The rest is just pure awesomeness!

Lessons Learned

Speeding things up

I've tried profiling, looking for bottlenecks, cutting out routes, removing gems, but nothing gave a significant speed up for Rails boot time. When running individual tests, spork gave a pretty good performance gain, but then a colleague pointed me to something better - zeus. It's a nifty thing that pre-boots various parts of rails and allows rapid execution for all those tasks that used to make me wait for 25 seconds. Running an individual test now takes 5 seconds instead of 30. Great success!

Tame the Zoo with Bootstrap Script

I've found a nice presentation by a GitHubber Zach Holman, which suggested using a script/bootstrap which would handle installing dependencies and more things that hurt newbies. Haven't done it yet, but I'm eventually going to write one.

Use the Right Tools

I started out with RubyMine - thought it would help me get around the code easier. It has a couple of goodies in it's pocket, but you can do nearly everything using good old Vim, proper shell and terminal - and you will have much more fun too. Use ctags to jump around the code like a boss. Lots of people are in love with Sublime, so it's worth checking out.

I've also found some tools that are very helpful for getting to know the application.

Rails Footnotes appends every page with a footer that contains lots of debug information and links that open your text editor with current controller, etc.

Pry is great for debugging. You just add binding.pry anywhere in your code and it stops with an interactive shell. Just like ipdb.set_trace does in Python. You can use pdb, but ipdb is better, but let's not get carried away. Also take a look at pry-nav, because for some weird reason pry alone won't give you the possibility to step around your code, and you should really want that.

Summary (last update: Oct 27, 2012)

  • Use zeus to get super fast Rails boot time.
  • Get some inspiration here and write a script for installing/starting/managing your development environment.
  • If you want to have more fun, don't use a heavy IDE. Use Sublime or vim. Here's my vim config.
  • Use ctags with your text editor (it should support the integration).
  • Use Pry and pry-nav gem to debug.
Ruby on Rails
comments powered by Disqus All posts