Bending typography preferences

I've noticed that my habits around spelling, punctuation, and use of whitespace are sometimes dictated by the tools I use rather than what I might otherwise prefer.

A prose example

An example in my prose is that I recently decided to use the British style for quotation marks next to a comma or period.

The American style always puts the comma or period inside the closing quotation mark:

You say "potato," I say "potahto." (American style)

The British style puts the comma or period on the outside when it isn't part of the thing being quoted:

You say "potato", I say "potahto". (British style)

I've been debating for a while whether to switch outright to British style, since I use it when I compose emails about programming, where punctuation characters appear in all sorts of odd places and it's important to be clear when a comma or period is not part of the code I'm quoting. For example, American style would look like this:

To add a level-2 header, type "<h2>," the header text, and "</h2>."

That looks way too much like you're being instructed to type a comma and period. Better is this:

To add a level-2 header, type "<h2>", the header text, and "</h2>".

The thing that convinced me to use British style everywhere, not just for code fragments, was my iPhone. In iOS, when you enter two spaces, it assumes you're ending a sentence and adds a period for you. So you type

That's all<space><space>

and iOS changes that to

That's all.

The problem arises when I end a sentence with a quote. I like to type two spaces between sentences, so I type

He said, "That's all."<space><space>

(note I have to type the "." myself) and iOS proceeds to add an unwanted period:

He said, "That's all.".

By using the British style I can type this:

He said, "That's all"<space><space>

and iOS will give me this:

He said, "That's all".

Maybe this could be fixed with a little added smarts in iOS where it could recognize the American style and not add another period. One of these days I'll file a Radar and see what happens. But for now, it's the perfect excuse for me to commit to British-style punctuation, and it's an example of my tools determining how I punctuate.

[Update: Rats, I just realized the last example above is incorrect, because the period is part of the thing being quoted. In both American and British styles, it should be

He said, "That's all."

So I guess I'll have to file that Radar.]

A coding example

In my personal Cocoa projects, I was thinking of adopting my employer's coding convention for instance variable names:

  • Weak references begin with a "w".
  • Outlets begin with an "o".
  • Everything else begins with an "m" (for "member"; never mind that this is a C++-ism).

Example:

@interface MyViewController : NSViewController
{
@private
    MyViewController * wOwningViewController;
    NSTextField *      oStatusTextField;
    NSMutableArray *   mSubViewControllers;
}
@property (readwrite, assign) IBOutlet NSTextField *statusTextField;
// ...
@end

It's handy to have these typographical reminders that you don't want to release wOwningViewController in your dealloc, and that you don't want to message oStatusTextField anywhere that might be called before the nib is loaded.

But then I got Kevin Callahan's Accessorizer, which is very handy for generating code that is tedious to type by hand, such as property declarations. You can select an ivar declaration and by hitting a couple of hotkeys you'll get the corresponding @property and @synthesize statements.

Accessorizer knows that an ivar name is often the same as a property name, except with a prefix added. For example, you can tell it that "_" is your prefix for ivars and when it sees

NSString *_name;

it will give you

@property (readwrite, copy) NSString * name;

and

@synthesize name = _name;

The problem is, you can only specify one prefix, and my employer's convention uses three different ones: "w", "o", and "m".

Now again, maybe this could be fixed with a little added smarts. There could be an option where Accessorizer assumes the first character, whatever it is, is the prefix. I've emailed Kevin about this, and for all I know this feature will appear someday. But for now I'm sticking with "_" as my prefix for all ivars, which I kind of like anyway.

Other coding examples

Accessorizer isn't the only software that has affected my coding conventions. I've adapted my commenting style (and I think one or two other things) to be compatible with what I get when I hit Reformat in Xcode. Some prominent blogger, I forget who, said he went along with Xcode's formatting — it wasn't worth the effort to prefer something different — and I realized he was right.

I've been on the fence about whether to use spaces or tabs to indent. Part of me leans toward spaces because I might want to copy code into blog entries, and I haven't found a good WordPress plugin for syntax-highlighting code that both handles Objective-C and handles 4-space tabs. Also, I might want to paste some of my code into an email, and most people's email readers will expand tabs to 8 spaces.

Speaking of syntax-highlighting plugins, if I can find the perfect one maybe I'll re-enable “smart quotes” in WordPress. I turned them off because I didn't want curly quotes accidentally showing up in source code that I paste here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.