April 2010 Archives

Literally quoting

| No TrackBacks

A lot of these newfangled languages (Python, JavaScript, etc.) support (at least) two types of string literals: double-quoted and single-quoted. The two don’t mean anything different.

Why not use this distinction to your advantage? I follow this rule:

  • “Double quotes” for literals that are English, or, more specifically, you can change these strings without consequence: console.log("Hello, World!")
  • ‘Single quotes’ for literals that can’t be changed willy nilly—these guys are tied to some code: $('p').show('slow')

Tell your team and unify all those quotes! It creates consistency, and also gives a hint to future developers as to what’s going on.

Syndication

Recent Trash