Underscores are so 90s

| | Comments (2)

Something unexpected I just learned: to many, it's now considered best-practice to use hyphens ( - ) instead of underscores ( _ ) when separating words in URLs. For example, instead of this:

http://example.com/fun_stuff/my_cats.html

You'd be better off doing this:

http://example.com/fun-stuff/my-cats.html

Why? Simple: Google recommends it. According to Matt Cutts, the big G will do a better job recognizing and indexing the words in your URL if you separate them with hyphens.

This has everything to do with search engine optimization (SEO), a term I tend to shy away from, what with its coming from the sinister realm of marketing versus the practical software architecture tack that I try to stick with. Sometimes the paths cross unexpectedly, though.

For me, this happened most recently as I set up a new Movable Type (4.23) instance for a client. I was surprised to find that, by default, it enforced that all files it created use dashes in their names instead of underscores. Googling on this topic led me to discussions from people asking how to get MT to use dashes in its filenames instead of underscores - the exact opposite of what I sought, but I was intrigued that so many should care. A little more searching led to this post on Google Inside, as well as the articles I linked to above.

I always approach the notion of work-pattern changes due to Google Fiat with a bit of skepticism, but this one's apparently settled into place globally over the last few years without my really noticing. Interesting, anyway.

2 Comments

Doug Orleans Author Profile Page said:

LiveJournal converts underscores in usernames to hyphens in URLs, but I thought that was a DNS thing (since each username gets a domain, e.g. foo-bar.livejournal.com). But maybe it's for Google too.

Also, I can type a hyphen on my Verizon phone, but not an underscore (as far as I can tell). (My G1 phone can do both, of course.)

I've always hated underscores, myself. Reminds me of the bad old days of K&R C programming. Scheme's custom is to have hyphens in symbol names, so that's how I tend to think. (And Scheme used to be case-independent, so you couldn't really do mixedCase. But I use that in Java and C++.)

Lee Stewart said:

I suppose using URLs like this is even worse: http://www.randomoddness.com/scripts/894/ (I'm hoping that my content "speaks for itself").

I've always liked underscores in variable names, camel_case annoys me. It's partially that I learned to program with it. But I also think it handles acronyms better (APILibrary versus api_library).

Leave a comment