Efficiently Develop Ruby on Rails Applications

by Nathaniel Rowe on September 8, 2016

Time is money. If this was a movie and I was a learned monk, I'd leave it at that, turn around and walk away into the mist, leaving you on a journey to figure out the full meaning and implications of that for yourself. But this is a brain dump of where I currently am in how I develop, so I'll go into the details of what I do to insure my time is well spent.

{% capture efficient-development-toc %}{% include series/efficient-development-toc.md %}{% endcapture %}
{{ efficient-development-toc | markdownify }}

How you Develop

This post is going to focus on the minute to minute of development work. The what's, why's and how's of pumping out code and overcoming barriers to putting that code down as well as addressing how to make sure you go into a project ready to rock and roll instead of being stuck on small issues.

Editor

I've tried tons of text editors through the years, I can say that Sublime is hands down the best I've come across. The following sections are what I really love about it.

Powerful user configuration

Below is my user config file, which I've tweaked here and there specifically for Rails work.

{
  "binary_file_patterns":
  [
    "log/*",
    "tmp/*",
    "cache/*",
    "bin/*",
    "vendor/*",
    "coverage/**/*",
    "public/assets/**/*",
    "*.map"
  ],
  "ensure_newline_at_eof_on_save": true,
  "file_exclude_patterns":
  [
    "*.map",
    "*.cache"
  ],
  "folder_exclude_patterns":
  [
    ".svn",
    ".git",
    ".hg",
    "CVS",
    ".sass-cache",
    "public/assets",
    "coverage"
  ],
  "font_size": 13,
  "ignored_packages":
  [
    "Vintage"
  ],
  "indent_guide_options":
  [
    "draw_normal",
    "draw_active"
  ],
  "tab_size": 2,
  "translate_tabs_to_spaces": true,
  "word_wrap": true
}
Hotkeys and functionality for everything

Whether it was vim, emacs, nano or another editor, I found they either didn't have the hotkeys I needed predefined, or that they were impossible to remember because there were to many options for a particular action. Sublime has everything I need, and what's more, they're super easy to remember and use. Time not spent digging through your editor's docs is time you can spend on development.

Some of my favorites:

  • Multi line edit
  • Project global find/replace
  • Open file find/replace

There are tons more, just go through sublime's docs to see everything it can do.

Package Manager & Packages

This is where Sublime really stretches its legs out. The package manager for it is flawless. Just open it, type what you're looking for and it will give a list of potential packages for your issue. Whether it's something mundane like highlighting for a file type such as Slim or mixed Ruby/HTML or something else, you can find it. The best part is that there's a huge community that creates these packages and uploads them so there's always something new and exciting, you just have to look.

As an example, one time I was writing some specs for a library that was testing values across large arrays. Basically, it came down it{expect(arr[0]).to eq(subject), but for hundreds of lines (terrible way to test, but this was the first round of a refactor and it needed some basic tests in place first). Now, wouldn't it be great if instead of copying and pasting that line hundreds of times and then manually entering each number I could get my editor to just generate those numbers for me? There's a package for that: Text-Pastry.

Sublime multiline sequential generator

That, combined with a multiline edit means you only have to select the correct amount of lines, type the expect line once, and then get the numbers generated for each line. It's a very scalable solution. There's tons of other tricks, and I could go on for thousands of words about individual use cases for multi line editing capabilities on Rails apps, but I'll save that for another post. For now, be creative and see if there's a package that can do what you need. You'll be glad you did.

List of the packages I use:
  • All Autocomplete
  • Better CoffeeScript
  • Cucumber
  • DashDoc
  • Gherkin (Cucumber Formatter)
  • GitGutter
  • KeyboardSpellCheck
  • MarkdownHighlighting
  • Package Control
  • Ruby Slim
  • SCSS
  • TextPastry
  • WordCount

Problem Solving

When I hit problems developing my rails apps, there's a 5 step solution I go through which solves > 99% of them:

  1. Read the stacktrace (most often a method typo, or an undefined method for nil class)
  2. Search stack overflow
  3. Google
  4. Read the docs (Rails or the Gem)
  5. Read the source code

Finally, if none of those work, phone a friend.

Digging into the source code can be strange the first few times, but get used to it. Once you've gotten good at finding solutions from understanding the underlying functionality, you not only come out with knowing a great deal more about the libraries you use, but you also run across new (to you) ways of implementing functionality.

Quickly finding solutions to your issues is the biggest time saver mentioned in this article. Quickly glancing at a stack trace and identifying the solution or finding the solution on Stack Overflow within 30 seconds will literally save hours a day. I used to lose tons of time running around blindly hacking on code to try and get it to work, and I see others do it constantly as well. This is something that only experience solves. Get in there, and get working on solutions to issues. Finding solutions to blockers will soon become a zen experience, it won't even be a bump in your flow, you'll just roll right over it.

Preknowledge

The final piece of developing efficiently is being able to solve problems before they become problems. Keep up to date on current Ruby/Rails bugs, gems, features and discussions. Even a little reading in your spare time each day goes a long way towards spotting issues with how you're operating in advance rather than fixing things after the fact. Here's a list of my essential places to keep up to date on what's going on to keep yourself in the know:

This isn't an exhaustive list, but it's where I get 90% of my reading.

I use Feedly to keep up with feeds.

Value

Add up all the times you've spent doing an inefficient version of any of the above activities that could have been better spent on something else. Whether it's a higher salary or bill rate, cutting out these development inefficiencies gives you a better case to both make more money for yourself, and to insure that your company and clients get the most out of what they spend on development work. A smart employer will recognize that you're worth it since the sooner products are released the sooner money is made. The goal of this post is to ensure that we as developers and consultants not only reach our full potential but that we can pass that value and happiness on to our clients at the end of the day.

Ruby On Rails

Let's Get In Touch!


Our best work gets done when we can work face-to-face with you.

770-317-4866