Nithin Bekal

Posts About Notes Slides

Single quotes or double quotes?

04 Feb 2014

The single quote has been under attack today. (In my team, at least). I saw this in the our team chatroom this morning:

Why do we need to follow the “always use single quotes, unless you need interpolation” rule in our coding conventions? Why not use double quotes everywhere?

What insolence! How dare anyone question a convention we have followed religiously for years months!

The community maintained Ruby style guide prefers the former, while the Github styleguide recommends the use of double quotes everywhere. Github’s convention does make sense. We need double quotes for interpolation anyway, so using them everywhere makes it consistent.

However, for me, a single quote says that the string doesn’t have any interpolation magic going on inside. When I see double quotes, I immediately scan the string for expressions that are being interpolated.

For now, I’ve managed to save the single quotes in our codebase. Frankly though, there is no “right” option here. As I’ve mentioned in a similar pointless rant on tabs vs spaces, pick whatever convention the team agrees on, and then follow it consistently.

So why did I spend half an hour in the chat room defending the single quote and then write a blog post about it, you ask? I’m wondering that myself.

Some Ruby style guides

Hi, I’m Nithin Bekal. I work at Shopify in Ottawa, Canada. Previously, co-founder of CrowdStudio.in and WowMakers. Ruby is my preferred programming language, and the topic of most of my articles here, but I'm also a big fan of Elixir. Tweet to me at @nithinbekal.