Repository navigation
Conversation
c3fc077 to
0ca1a54
Compare
|
Hello, I'd like to suggest a minor modification that would be rather practical. The aim is to be able to easily distinguish between 0 ULIDs. It's the same principle as for the UUID library (https://github.com/google/uuid). |
| type ULID [16]byte | ||
|
|
||
| var ( | ||
| Nil ULID // empty ULID, all zeros |
There was a problem hiding this comment.
A ULID that's all zeroes is AFAIK valid, and so isn't really accurately called a "nil" ULID. At a minimum, this should be called Zero ULID. Even then, I'm not sure what purpose this definition would serve. Any application that accepts a ulid.ULID shouldn't in general treat a Zero ULID differently than any other ULID. Do you have some use case that would indicate otherwise?
There was a problem hiding this comment.
+1 for naming, Zero (and maybe a isZero() getter as in time library) will be better. I've several usecases where ULIDs are not already set and I avoid a lot of using pointers in my domain structs.
There was a problem hiding this comment.
It's important to understand that var Zero ulid.ULID — which is ultimately a [16]byte of all-zeroes — is a completely valid ULID value, and cannot be treated as any kind of "nil" or otherwise invalid ULID value. If you want to distinguish invalid vs. valid ULID values, you cannot model them as specific values of the ulid.ULID type.
There was a problem hiding this comment.
I understand and agree completely. In fact, I don't have any use cases where a zero-filled ULID is valid (they all start well after timestamp 0). So you recommend using a pointer to be totally sure of initialization ?
There was a problem hiding this comment.
If your application wants to treat a zero value ULID as invalid, no problem! I'm just not sure about treating this specific ULID value as special in the actual module.
| type ULID [16]byte | ||
|
|
||
| var ( | ||
| Zero ULID // empty ULID, all zeros |
There was a problem hiding this comment.
AFAIK this is a completely valid ULID, so it can't be treated as a distinct/invalid value by consumers — right? Do you disagree?
|
The UUID RFC defines an all-zero UUID as a special case, which it calls a nil UUID. But ULID doesn't define an all-zero ULID in any special way, to be an e.g. nil ULID, AFAIK. |
|
Ok, with your permission, I'll close this PR, it's seems to be out of the scope of this module :) |
Same behavior as https://github.com/google/uuid