4 ms·
> The great advantage of being standardized is that other people have thought about these issues and dealt with them in libraries. Issues that don't exist if y
by TazeTSchnitzel 11y ago
> The great advantage of being standardized is that other people have thought about these issues and dealt with them in libraries.
Issues that don't exist if you don't use a hideously complex format like UUID in the first place.
> Yes there are many bad ways to generate them, but your library should offer the right way to generate them.
Yes, a UUID library will have a way to generate the random kind of UUID, but it's telling that you need a library for it.
You can generate 16 random bytes without a library, by using fopen() and fread().
> Yes the string format is weird, but why would you write that by hand? Let the library print it, let the library parse it.
You shouldn't need a library to handle your identifiers. If you do, your identifiers are too complicated.
> Want to store it in a database? There's a column type for that. Want to send it over the network? There's probably a datatype for it in whatever protocol you're using (whereas with your approach you immediately have endianness issues).
With the approach of random bytes, there's at least a consistent endianness throughout. And you can solve the endianness issue by treating it as a byte string. Job done.
- lmm 11y ago> You can generate 16 random bytes without a library, by using fopen() and fread(). Sounds more complicated and easier to get wrong. I'd rather have a single function call with an obvious name.
- GFK_of_xmaspast 11y ago> You can generate 16 random bytes without a library, by using fopen() and fread(). Yeah but then good luck getting the right /dev/random vs /dev/urandom on the right platform, and also good luck getting it to work on windows and ios.
- TazeTSchnitzel 11y agoTrue, it has its caveats.
- dalke 11y agoAnd good luck if you are in a chroot'ed jail, or out of file handles. (Hence why OpenBSD added arc4random(), now based on ChaCha20.)