4 ms·
Why would you format it as a UUIDv4 instead of just leaving all bits intact?
by MichaelGG 9y ago
Why would you format it as a UUIDv4 instead of just leaving all bits intact?
- ivan_gammel 9y agoWell, that's possible, but I'd say it's generally better to keep close to the spec and v4 is the closest option here.
- MichaelGG 9y agoBut what's the value in the "spec" here? I see people mentioning this and I'm wondering what the rationale is.
- cronjobber 9y agoThe rationale is that you can use them along with those other versions of UUID that contain nonrandom data. Assume Bob uses one such not-entirely-random UUID variety and actually makes use of the embedded information. Charlie uses random UUID. Bob and Charlie merge their data. If Charlie had filled the version bits with random garbage, the merge would poison Bob's use of the embedded information. Basically, UUIDs are a discriminated union type.
- ivan_gammel 9y agoThanks, that's the best answer.
- concede_pluto 9y agoBy violating the spec you're assuming you'll never want to use a tool that strictly adheres to the spec. Postel's Law works best because it accommodates some people not following it.
- imhoguy 9y agoTo take advantage of native UUID support in a database, e.g. PostgreSQL stores them in 128 bits. Also every UUID carries version number so minimal formating needs to be performed to comply with the standard.
- MichaelGG 9y agoSo you're saying Postgres actually wastes cycles verifying the version information and doesn't treat UUID just as a 16 byte opaque structure?
- anarazel 9y agoWell, there's the "input format" (or rather two), which gets parsed into the internal representation. The input format can be either hex text, which allows dashes in some positions, or binary, in which it's just a bytearray. There's no verification otherwise, unless you treat generation of UUIDs, which allows to specify the type, as such.
- anarazel 9y agoSecond point: Verifying version information would hardly matter cyclewise.
- nvivo 9y agoI'm not sure what you mean exactly. The textual representation of an UUID HAS all the bits intact. UUID formatting is not lossy compression.
- MichaelGG 9y agoUUID v4 "spec" leaves 122 bits for randomness and has 6 fixed bits for "version" information. I'm suggesting that following the spec on such stuff is a total waste and serves no point, and you're better off with a random 128-bit number.
- nvivo 9y agoWell, then it's not an UUID. It's just 128 random bits. If you just want to be the most random possible, you can go 256, 512, 1024, etc. That may be what you want, but you can't say UUID v4 is a "total waste" or "serves no point". It's purpose is to never collide with another UUID v4, not to be the most unique value ever.
- MichaelGG 9y agoUUIDv4 is a 122 bit random number. Having another 6 random bits won't make them collide. Also if there's UUIDs in your system colliding with a 128 bit random numbers then the rng is broken or your UUID generator would be great to crack encryption keys.