Use the typographically-correct quotation characters — ‘ ’ “ ” — inside strings rather than the easy-to-type straight quotes. Not only will it look better, it wont require escaping or remembering to alternate when nesting.
OS X has default key bindings for these characters, but they don’t make sense. Save the following snippet as ~/Library/KeyBindings/DefaultKeyBinding.dict
to create custom ⌥ key bindings on the [ ] { } keys for these characters.
{
"~[" = ("insertText:", "‘");
"~]" = ("insertText:", "’");
"~{" = ("insertText:", "“");
"~}" = ("insertText:", "”");
}
This will make ⌥[ and ⌥] insert open and close single quotes, and ⌥{ and ⌥} insert open and close double quotes (like god intended). You must restart for this to take effect.
For more pedantic fun, check out a more comprehensive list of common bad typography habits.