Subscribe to
Posts
Comments
NSLog(); Header Image

Agile Web Developers Like Double Quotes

A friend of mine gave me the PDF version of the Agile Web Development book I've been reading (I own the full verison, but it's easier to view a PDF when you're writing code than to go back and forth from book to screen), and one question keeps popping up: why, if '' takes less to process than "", do the authors keep using "" when it's not needed?

<%= error_messages_for("order") %>

Perhaps I'm being silly, or I'm over-optimizing, but wouldn't that be at least a little better as:

<%= error_messages_for('order') %>

Most of the PHP I've ever written only dips into double quotes when necessary - string replacement, etc. The same capability exists in Ruby, and likewise at the cost of processing. So, over-optimizing or just being silly?

P.S. Just noticed this errata, which talks about some confusing text, but also points out:

FWIW, you use three different styles to call e_m_f throughout the book - single-quote with no parens, double-quote with parens, symbol name.

It's true, the line above can be written in a number of ways. The authors, however, seem to prefer the double quote method, even when it's unnecessary.

4 Responses to "Agile Web Developers Like Double Quotes"

  1. Well, I'd say your kind of over-optimizing here 😉 But I'm actually against using double quotes when they're not needed as well. I doubt I'd criticize a book for it though, I'd just write it down as another one of the annoying stylistic things I do different from the authors. You don't loose _that_ much performance with double quotes vs. single quotes, and for most devs it won't matter a single bit.

    What I'm more afraid of, are those taking double quotes for "best practices" whenever and wherever, leading to extremely nasty string escaping when it's not even necessary (especially when writing HTML tags with attributes).

  2. I guess double quotes are used that often because the look more naturally. In non-programming languages you don't often see something encapsulated in single quotes, so it might just be a bad habbit. And the performance gain of using single quotes is so small - but on the other hand optimizing has to start somewhere, and even a small gain is a gain, so I also use single quotes when coding. Btw: In the above example it would even be ruby-like to use a symbol, (:order) instead of a string

  3. If you're used to programming in C then it's natural to use double-quotes for string constants, because in C single quotes are for single-char constants only. It becomes a difficult habit to break even if it's not optimal.

  4. Maybe it is just a "C" habit. Or C++, Java and most C-like languages. PHP excepted. 🙂