Andy Waite

Software Development Consultant, London

Ruby and Rails Resources for Intermediate to Advanced Developers

23 May 2015

A recent post on Reddit asked about how an experienced developer can improve their Rails knowledge.

There’s an abundance of resources online for those looking to pick up the basics of building a Rails app. But once you get beyond that, finding good quality content takes some effort.

I’ve been writing Rails code professionally for around six years. In this post, I’ve listed the resources which have been most useful to me over that time.

None of these resources are free. Paying for them is a high-return investment in yourself. If you work as an employee of a company, most will have a training budget per employee, so ask them to contribute.

Books

Ebooks

Videos

Improve Your Workflow by Avoiding Conflated Commits

17 May 2015

There are two simple maxims which have had a huge impact on how I write code:

Always check a module in cleaner than when you checked it out.Uncle Bob

For each desired change, make the change easy (warning: this may be hard), then make the easy changeKent Beck

These have led to the following principle which I apply whenever committing code:

A single commit on the mainline branch should be either an improvement to the structure of existing code, or a change in behaviour, but not both.

Here’s why:

Separate commits are easier to review

Git’s diff is pretty smart, but it’s not perfect. It often can’t distinguish between code which is new and code which has been moved around. This makes changes more difficult to review. By using separate commits, the reviewer can examine each diff separately, making it easier to understand what’s changed.

Separate commits improve Continuous Integration

If a conflated commit breaks the build, it’s often not clear whether it was the clean-up or the behaviour change which is to blame. Distinct commits help to pinpoint the cause of the breakage.

Separate commits reduce waste

Sometimes there’s a need to rollback a commit. The git revert subcommand applies a new commit which reverses the changes made in a given commit. If that commit was responsible for restructuring some existing code, as well as changing behaviour, then we’d lose out on the benefit of that clean-up.

Separate commits are git-friendly

The git bisect command helps to discover when a defect was introduced. Using separate commits makes this more effective.

Separate commits give a clearer history

The commits on a file should give a clear history of how the file has changed over time. Keeping the commits focussed make this easier to understand.

Treating ActiveRecord as a private interface with FigLeaf

01 May 2015

In Objects on Rails, Avdi Grimm talks about treating ActiveRecord as a private implementation detail.

I’ve been aiming to do this in my own code for some time now. And I’ve worked for clients on many struggling, legacy Rails projects where following this simple guideline would have saved a lot of pain.

I was curious to see if I could programatically enforce this convention on a real project, using the fig-leaf gem introduced by the book.

Goodbye Octopress

29 April 2015

I moved to Octopress several years ago but I’ve always found it somewhat confusing. I’ve now switched to using plain Jekyll via GitHub Pages. Things may look a little rough at the moment.

Opening new panes in tmate

01 March 2015

tmate is a fork of tmux for easily setting up a remote pairing session. When using normal tmux, I have the following configuration so that new panes and windows remember the previous working path:

bind-key - split-window -v  -c '#{pane_current_path}'
bind-key \ split-window -h  -c '#{pane_current_path}'
bind c new-window -c '#{pane_current_path}'

I recently tried remote pairing in tmate for the first time. It was confused as to why my new panes and windows were opening in the top level / instead of the previous pane’s path.

It turns out that pane_current_path is a tmux 1.9 feature, but tmate is based on tmux 1.8. There’s some talk of a 1.9 version, but it seems to have been delayed.

The workaround I’ve found is to use -c "$PWD" instead. Make sure to use double quotes so that it gets interpolated. You can add that to ~/.tmate.conf to override the existing setting in ~/.tmux.conf.