The vast majority of English speakers overlook difference in how dashes are used, thinking all dashes are equal. They are not. There are actually three types of dashes commonly used in literature, each with their own name and “approved” usage. The standard dash, the one on your keyboard, is actually a hyphen. It is the most commonly used, most often to connect compound words like merry-go-round, or to make sure that multiple-word descriptors are understood correctly. (Did you catch the use of that hyphen?)
Two other common dashes are the en dash and the em dash. The only physical difference is in length. The en dash (–) is longer than a hyphen, and the em dash (—) is longer still. An en dash is generally used in place of a hyphen to designate a range, such as a reference to something that appears on pages 12–23. There are no spaces between characters and dashes, which makes sense, because it is designed to physically link one set of characters to another.
So what of the em dash? It is most typically used to set apart a portion of a sentence, instead of using a comma, semi-colon, or parenthesis. The general convention is to use the em dash without spaces before or after. I am not a fan. The first problem—the minor point—is the excessive length. It looks like material is missing, as if it is a blank, underlined so it can be filled in. If forced to choose between and em dash and a parenthesis for a parenthetical statement, I will choose the later.
The second problem (the major point) is the counter-productive visual effect of missing spaces. Without spaces, it gives the appearance that the words on either side of the em dash are linked, when exactly the opposite is intended by the writer. The effect gets magnified when paragraphs are fully justified, resulting in larger than normal spacing between words in some sentences. Consider this line from a published sci-fi, with full justification on a short page (on a Kindle).
“The Federates might take vengeance on her, and—he swallowed—himself.”
Is this character fearful that he will be swallowed up in the Federation’s vengeance, or that he will swallow himself? The intention of the author is the former. The visual effect is the latter. The sentence written with en dashes and spaces on the same page with the same formatting looks like this.
“The Federates might take vengeance on her, and – he swallowed – himself.”
Down with the Em. Up with the En!