Be Unique But Don’t Be A GUIDJun 15, 2011 In Development By Karsten Januszewski
Guids. As in globally unique identifiers. Love 'em. And hate 'em.
I mean , you gotta admit, they're kinda cool. Like fingerprints. Or snowflakes. But unlike snowflakes or fingerprints created through the magic of nature, the GUID can be created by me, the software developer! I have the power!
In fact, who wants to play GUID lotto? Here's how it works. I'll generate two GUIDs. If they match, you win! Note: odds of winning are 1 in 2128!
Hours of fun await you.
The problem is, GUIDs are so easy to generate that people -- or I should say, software developers -- tend to fall back on them as a default solution whenever one needs a unique key. Have a row in a database? It must need a GUID!
I'm not sure when this proliferation of GUIDs started. Perhaps we can blame COM. (There's a lot we can blame COM on. Quick: what's the GUID for IUnknown?) Or perhaps it is the GUID generator in Visual Studio:
The crux of my problem with GUIDs isn't technical; it's aesthetic. They're just so darn ugly. And they make really unsightly URLs. I don't want to look at them. Yours. Mine. Anyone's. Keep those GUIDs away from me!
So, I urge all of you software developers—including Microsoft employees who tend to use GUIDs egregiously—to think twice before you start using GUIDs. There are many other options to generate a unique key that isn't globally unique. And if you've got a case where you must use GUIDs, please keep them hidden from the user. I don't want to see your GUID, por favor.