Am I correct on saying that this isn't a guid cos it uses the whole alphabet while a guid is just hex? The method doesn't imply that it's a guid either, but the resulting string is formatted like one, which is... weird.
Yup, and I know for a fact that it’s meant to be a GUID/UUID, which is sad. What is worse is that the server (the picture is from the client) accepts it
How often do people rewrite built in functionality that's much slower, and likely less random, because they were too lazy to even look to see if, say, System.Guid exists? Too often... way too often...
There have been a few built-in functions that I just didn't know existed until I had written my own function and somebody pointed it out to me; it is almost impossible to know ever single function of a language.
When there’s something I have no idea how to implement, I usually google “<language> <item>”, in this case “C# uuid”, I’m sure System.Guid would be a top result
When there’s something that I have a great idea of how to implement, but seems like a reasonably common thing, I also Google it. Because I’m just that lazy.
Yes that's also what I meant. The code in libraries is bulletproof because it has faced every situations that we can't always anticipate. It's their main purpose: do one thing, perfectly, without failing. And let developers put their efforts on business-specific algorithms.
Software has been generating GUIDs based on clearly-prescribed rules (which the above doesn't respect) for more than 30 years. It's been a core part of broadly-used technologies like COM for 25+ years, and DB, messaging, and web service / microservice technologies for almost as long.
Any language or framework updated anytime since Clinton was reelected would include a validated way to generate a GUID.
There's an easy way out. Ask yourself: Am I solving a problem that most likely 1000+ developers had to solve before me? If the answer is yes, there's at least a thread on stackoverflow discussing how it should be done. Or a publicly available library for that. And if you don't like anything of what you see, improve: add an answer to SO, contribute to the open source.
But no, that's not what guids those kind of devs. It's laziness and ignorance. Cowboying it is. Just mash something together and call it a day.
We weren't allowed to use stuff like the STL containers in my Data Structures class. There's an ok reason for it: it was so we could get a feel for how everything worked, but whenever I need an array I have trouble kicking the habit of initializing it the old- fashioned way.
To reinvent the wheel is to duplicate a basic method that has already previously been created or optimized by others. The inspiration for this idiomatic metaphor lies in the fact that the wheel is the archetype of human ingenuity, both by virtue of the added power and flexibility it affords its users, and also in the ancient origins which allow it to underlie much, if not all, of modern technology. As it has already been invented and is not considered to have any operational flaws, an attempt to reinvent it would be pointless and add no value to the object, and would be a waste of time, diverting the investigator's resources from possibly more worthy goals.
When it comes to cryptography and rng, never ever roll your own. If you understand even the basics of encryption, you know why, and if you think you know better, you need to study it more.
UUID4 doesn't actually guaranteed the UU part, it just makes it extremely likely to be unique (122 bits of random).
UUID3 and UUID5 guarantee it, so long as the inputs are unique - aka, these are fully determinist UUIDs.
UUID1 and UUID2 are guaranteed to be UU within all possible parameters, so long as RFC 4122's option to use a non-MAC address is not applied. If that option is applied, it, again, just makes it extremely unlikely to be duplicated (48 bits of random+date/time).
A universally unique identifier (UUID) is a 128-bit label used for information in computer systems. The term globally unique identifier (GUID) is also used, often in software created by Microsoft. When generated according to the standard methods, UUIDs are, for practical purposes, unique. Their uniqueness does not depend on a central registration authority or coordination between the parties generating them, unlike most other numbering schemes.
85
u/[deleted] Aug 16 '21
Am I correct on saying that this isn't a guid cos it uses the whole alphabet while a guid is just hex? The method doesn't imply that it's a guid either, but the resulting string is formatted like one, which is... weird.
38
u/r0ut66 Aug 16 '21
Please tell him about
Guid.NewGuid()259
u/[deleted] Aug 16 '21
How often do people rewrite built in functionality that's much slower, and likely less random, because they were too lazy to even look to see if, say, System.Guid exists? Too often... way too often...
3
u/BrackGin Aug 16 '21
Did you hate him the most before or after you saw this code?
24
u/MeatyLabia Aug 16 '21
People that concat inside a stringbuilder hurt my soul.
24
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 16 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
7
u/asaf92 Aug 16 '21
Ha yes, reinventing the square wheel
4
u/thanatica Aug 16 '21
If only there was a built-in function that would return a random UUID using proper cryptographic randomness... Oh wait.
1
u/DutchBookOptions Aug 16 '21
Was it you OP?
1
u/speedingpeanut Aug 16 '21
Hey at least they used StringBuilder
1
u/TurnipsAreFlat Aug 17 '21
Was this person by any chance yourself?
3
u/distractedNightOwl Aug 16 '21
Anyhow, the result is random - but also unique?!?!? :D
2
u/Syscrush Aug 16 '21
Well, for what it's worth, I now also hate that person.
2
u/Gonzo345 Aug 16 '21
Reinventing the System.Guid
2
u/Sol3141 Aug 17 '21
When it comes to cryptography and rng, never ever roll your own. If you understand even the basics of encryption, you know why, and if you think you know better, you need to study it more.
0
u/planktonfun Aug 16 '21
efficient how?
0
u/Eoussama Aug 16 '21
C# was not made for this code but ppl always find a way.
-9
u/Voltra_Neo Aug 16 '21
*ID, the point of UUID is to be Universally Unique
0
u/[deleted] Aug 16 '21
[deleted] — view deleted comment