• Tinkle (unregistered)

    You do not need to check the documentation, you just need to know that Guid is a struct

    The default constructor on a struct will always create a zero initialised struct.

  • (nodebb)

    That's what they get for thinking of UUIDs as strings. They are and always have been 128 bit numbers that are rendered as dashed hex strings because they're shorter and because human brains malfunction in the presence of anything with more than 3 digits, which incidentallly is why we had to invent thousands separators.

  • (nodebb)

    human brains malfunction in the presence of anything with more than 3 digits

    So sayeth AGlezB in the year 2026.

  • JPJ (unregistered)
    Comment held for moderation.
  • Robin (unregistered)

    Let me guess, the fix was adding a 4th "0" to the string (maybe a 5th if they were feeling particularly virtuous), to make an accidental hit "virtually impossible" :D

    [Confession: I know essentially nothing about how GUIDs/UUIDs are actually generated - I've never needed to - but even I thought, on seeing that code, "what's special about 3 0's? Surely that could easily come up in practice?".]

  • (nodebb)

    Someone's going to mention an ethernet card MAC address and we've gone down a stupid rabbit hole.

  • Hmmmm 🤨 (unregistered)
    Comment held for moderation.
  • (nodebb) in reply to Robin

    Let me guess, the fix was adding a 4th "0" to the string (maybe a 5th if they were feeling particularly virtuous), to make an accidental hit "virtually impossible" :D

    Even if the test for three zeroes is correct (it isn't), it's wrong anyway, unless the caller is careful to "toString()" the Guid using the "N" format (just a string of digits). The default is "D", "8 digits hyphen four digits hyphen four digits hyphen four digits hyphen twelve digits", and the other formats are even worse. If the three zeroes cross a hyphen ("...00-0..."), they won't be detected.

    In the end, all that's necessary is to compare the Guid to Guid.Empty or new Guid().

  • (nodebb)

    An ex-colleague of mine forced me down the MAC address hole. Fortunately I had reviewed the RFCs before going into that discussion

  • Cheap, Fast, Right. Pick any empty set (unregistered)

    I've seen 'homebrew' implementations of globally unique identifiers such as "CRC32", "start at 0 and increment a counter" in the kind of industries where there's major property damage or death when things go bad.

    In one case when I pointed out there's nothing globally unique about the 'incremeting counter' approach I was told. "Yeah, but it gets people used to thinking in terms of the idea of GUIDs, which we'll implement in the future".

    Another case where the CRC32 of a blob of data was being used as the primary key to a database. The database was being updated with new values a few thousand times per minute (it was really an overengineered logging aggregator for devices all over the country). They couldn't figure out why a couple times a month there was an insertion failure. Had to explain the birthday paradox to them. Worse yet they weren't actually querying the database by the key. They were selecting on some other field entirely. I was never able to get an answer as to why they did what they did. I suspect it was some misguided de-duplication logic.

Leave a comment on “Unique Testing”

Log In or post as a guest

Replying to comment #704855:

« Return to Article