27 January 2009

n-dash VS m-dash

The good thing with software engineering is that you learn a new thing every day. Computer programs depend on so many different layers, libraries, hardware that it should be no surprise that things go wrong all the time.

One of the Agile practice to fight this entropy is unit testing and especially Test Driven Development (TDD). Since 2005, I work with TDD, writing the specs (tests) before the code and this is the best design method I have used so far! No more dead code :-) Moreover, the final code looks really clean and the tests are the best up to date documentation with examples I will ever write.

I am implementing a Schedule class which encapsulate event times such as in the flavorpill.com. Following TDD and being lazy(!), I wrote the spec first so I copy pasted directly the "When" text from the event page in flavorpill to my editor:


it "should output in a pretty format such as Tuesdays–Sundays (10am–5pm)" do
@schedule.starts_at = 10.am
@schedule.ends_at = 5.pm
@schedule.from_tuesday.to_sunday
@schedule.pretty_format.should equal("Tuesdays–Sundays (10am–5pm)")
end

=>expected "Tuesdays–Sundays (10am–5pm)", got "Tuesdays-Sundays (10am-5pm)" (using .equal?)

Don't you see the difference? Me neither, and it took me at least 5 minutes to understand what was going wrong.

After increasing the size of the font, it's a bit easier to spot:

expected "Tuesdays–Sundays (10am–5pm)", got "Tuesdays-Sundays (10am-5pm)"

Olala! A colleague of mine who works as an editor introduced me to the wonderful world of n-dash and m-dash.

The hyphen is used to hyphenate compound words and between non-continuing numbers, e.g., phone numbers.

The en dash - is used to "connect continuing, or inclusive, numbers -- dates, time, or reference numbers." [Chicago Manual of Style, sec. 5.115]

The em dash is used "to denote a sudden break in thought that causes an abrupt change in sentence structure." [Chicago Manual of Style, sec. 5.106]

Morality: copy-paste is evil!

But be honest, who knows about these characters, did you learn it in english classes? As far as I am concerned, there is no key in the keyboard to type the m-dash...

No comments: