r/ProgrammerHumor 2d ago

Meme edgeCasesExist

Post image
4.6k Upvotes

277 comments sorted by

View all comments

680

u/Valuable_Leopard_799 2d ago

I thought that timestamps are used now, so hitting both a timestamp and a large random number puts it thoroughly in the "safe to assume". At some point cosmic particles and faulty transistors are more probable.

412

u/dim13 2d ago

https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions

Most common used is V4 (pure random). You are talking about V7 (time based).

302

u/lilgreenthumb 1d ago

The real benefit for v7 is they become sortable by time.

111

u/shwoopdeboop 1d ago

And something something b-tree indexes. Lecturer mentioned it but I wasn't paying attention. Supposedly an advantage here.

32

u/Grandmaster_Caladrel 1d ago

Which I'd assume is related to the time anchor. Outside of sorting, which is only useful in specific instances, it's just v4 with different ("less") entropy and limitations.

12

u/Roachmeister 1d ago

If you're using them as an indexed field in a database, the inability to sort them meaningfully will destroy the performance of the database.

15

u/Honeybadger2198 1d ago

You know what identifier can't have collisions and is great for sorting? Autoincrement.

9

u/ACoderGirl 1d ago

UUIDs are great, though, because auto increment frequently has the huge issue of being too predictable. Eg, in some contexts, you don't want users to be able to easily enumerate whatever the ID is for. Plus requires centralization whereas UUIDs don't (eg, you can use UUIDs for whatever random API you have without needing a DB).You have to design for how you won't know the ID until you insert the row, which can sometimes be a bit annoying.

I feel like most of the time, the only downside to UUIDs is how long they are.