Dashes, underscores, or periods?

This is a highly opinionated topic (the following video completely sums it up), so feel free to agree/disagree with me. 🙂

When working with files that eventually end up on the Web, there is an age-old debate over whether to use dashes or underscores in the place of spaces in file names. Using spaces in file names is highly discouraged, as the special character representing a space (%20) often breaks in chats and messaging clients, creating an invalid URL, and are generally considered annoying URLs (much like spaces in file paths are in programming). So what is a good replacement character for a space? In this post, we will be briefly exploring the use of dashes, spaces, and periods as replacements for spaces in URLs. As already stated, since this topic is based on personal preference you are obviously free to choose whatever replacement you want. 🙂

Dashes

In URLs, dashes are interpreted literally, meaning there is not a special character for it. So instead of a URL with spaces in it, such as

http://mywebsite.com/images/this%20is%20an%20image.jpg

it is now

http://mywebsite.com/images/this-is-an-image.jpg

From my experience, dashes work the best, as they ar easier to type (especially on mobile keyboards) and look the nicest.

Underscores

Underscores are also interpreted literally, so no special character to worry about. The same URL using underscores looks like

http://mywebsite.com/images/this_is_an_image.jpg

On both full-size and mobile keyboards, an underscore is only accessed through a modifier key, so it is a bit harder to type.

Periods

Unlike dashes and underscores, periods are actually represented by a special character, %2E. Therefore, they are subject to the same issues as spaces, especially when they are at the end of a URL. I cannot count the number of times I have seen URLs that end with periods just to have that trailing period break the entire URL. For completeness, our example URL with periods as separators would look like

http://mywebsite.com/images/this%2Eis%2Ean%2Eimage.jpg

Bonus Item! Nothing

What if you use no separator? What would happen then? Nothing! With your URL like

http://mywebsite.com/images/thisisanimage.jpg

you have none of the issues spaces create. However, for really long URLs, this can make them hard to read and get a quick idea of what it is (oh, you did not know URLs are supposed to actually give a hint of what it points to, did you?). You would probably save this one for super short URLs, like ones you get from URL shortening services. 😉

-le717

Advertisements

One thought on “Dashes, underscores, or periods?

Triangular Reactions

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s