News for hackers. Stuff that matters.
Re:Type-safe, K-sortable, globally unique identifier inspire... by klabb3 on Wednesday June 28, 2023 @06:05PM (#36513283)
A couple of suggestions:

Lock down the prefix string now before it’s too late and document it. I see in Go that it’s lowercase ascii, which seems fine except for compound types (like “article-comment”). May be worth looking at allowing a single separator given that many complex projects (and ORMs) can’t avoid them.

The Go implementation has no tests. This is very unit-testable. Add tests goddammit!

For Go, I’d align with Googles UUID implementation, with proper parse functions and an internal byte array instead of strings. Strings are for rendering (and in your case, the prefix). Right now, it looks like the parsing is too permissive, and goes into generation mode if the suffix is empty. And the SplitN+index thing will panic if no underscores, no? Anyway, tests will tell.

As for the actual design decisions, I tried to poke holes but I fold! I think this strikes the sweet spot between the different tradeoffs. Well done!

Re:Type-safe, K-sortable, globally unique identifier inspire... by avgcorrection on Wednesday June 28, 2023 @06:11PM (#36513349)
> The Go implementation has no tests. This is very unit-testable. Add tests goddammit!

Yep. The readme asks people to provide other implementations. Having a test suite would be good for third-party code.

Re:Type-safe, K-sortable, globally unique identifier inspire... by tomcam on Wednesday June 28, 2023 @06:34PM (#36513582)
> Add tests goddammit!

Hey, you’re pretty smart. How about you add them?

Re:Type-safe, K-sortable, globally unique identifier inspire... by klabb3 on Wednesday June 28, 2023 @06:54PM (#36513805)
I’m by no means a test police. I’m in fact opposed to a lot of mindless testing for the sake of it. But there are places where unit tests shine, and this is one of them.

If you mean that criticism is only allowed if you are willing to commit labor, I disagree with that. I always welcome critique myself - it may be something that I’ve missed. The maintainers always has the last word. As long as there are no hidden expectations, it’s all good.

Re:Type-safe, K-sortable, globally unique identifier inspire... by tomcam on Thursday June 29, 2023 @11:55PM (#36530343)
Do you need to be “test police“ to add tests you literally demanded of them?
Re:Type-safe, K-sortable, globally unique identifier inspire... by dloreto on Wednesday June 28, 2023 @06:52PM (#36513775)
Thanks for the feedback!

We have tests for the base32 encoding which is the most complicated part of the implementation (https://github.com/jetpack-io/typeid-go/blob/main/base32/bas...) but your point stands. We'll add a more rigorous test suite (particularly as the number of implementations across different languages grows, and we want to make sure all the implementations are compatible with each other)

Re: prefix, is the concern that I haven't defined the allowed character set as part of the spec?

Re:Type-safe, K-sortable, globally unique identifier inspire... by klabb3 on Wednesday June 28, 2023 @07:05PM (#36513919)
> We have tests for the base32 encoding which is the most complicated part of the implementation

I didn’t look into it much but it seems like a great encoding even outside of this project. Predictable length, reasonable density, “double clickable” etc. I’ve been annoyed with both hex and base64 for a while so it’s pretty cool just by itself.

> Re: prefix, is the concern that I haven't defined the allowed character set as part of the spec?

Yeah, the worry is almost entirely “subtle deviations across stacks”, which is usually due to ambiguous specs. It’s so annoying when there’s minor differences, compatibility options etc (like base64 which has another “URL-friendly” encoding - ugh).

Re:Type-safe, K-sortable, globally unique identifier inspire... by aftbit on Wednesday June 28, 2023 @07:30PM (#36514182)
My personal favorite encoding is base58 aka Bitcoin address encoding. It uses characters [A-Za-z0-9] except for [0OIl]. It is almost as dense as base64, "double clickable", but not (as) predictable in length as base32.

It was chosen to avoid a number of the most annoying ambiguous letter shapes for hand-entry of long address strings.

https://en.bitcoin.it/wiki/Base58Check_encoding

Re:Type-safe, K-sortable, globally unique identifier inspire... by bredren on Wednesday June 28, 2023 @08:17PM (#36514642)
Reminds me that Windows activation keys used to exclude a broader set of characters to avoid transcription errors: looking it up again: 0OI1 and 5AELNSUZ
Re:Type-safe, K-sortable, globally unique identifier inspire... by unshavedyak on Wednesday June 28, 2023 @10:44PM (#36515720)
Is there a good reason why Base63 (nopad) doesn't exist? Ie Base64 minus the `-`, so that you almost get the density of base64 (nopad) but the double click friendly feature.

I was reviewing encodings recently and didn't want to drop all the way down to base32, but for some reason the library i was using didn't allow anything beyond base32 and bas64 variants, despite having a feature where you can define your own base.

I thought maybe it was performance oriented. An odd prefix length like base63 would mean .. i think, a slightly more computationally demanding set of encoding instructions?

Either way i basically want base58 but i don't care about legibility, i just wanted double click and url friendly characters.

Re:Type-safe, K-sortable, globally unique identifier inspire... by TedDoesntTalk on Wednesday June 28, 2023 @11:48PM (#36516085)
It’s not too difficult to write your own encoding. Probably 10 lines of code or less if you hard-code your encoding alphabet.
Re:Type-safe, K-sortable, globally unique identifier inspire... by fauigerzigerk on Thursday June 29, 2023 @03:14AM (#36517384)
>Is there a good reason why Base63 (nopad) doesn't exist? Ie Base64 minus the `-`, so that you almost get the density of base64 (nopad) but the double click friendly feature.

Yes, the reason is that you need 64 characters if you want each character to encode 6 bits as log2(64) == 6. If you only have 63 characters in your alphabet then one of your 6-bit combinations has no character to represent it.

Base32 can represent 5 bits per character because log2(32) == 5. Anything in between 32 and 64 doesn't buy you anything because there is no integer between 5 and 6.

Re:Type-safe, K-sortable, globally unique identifier inspire... by unshavedyak on Thursday June 29, 2023 @10:09AM (#36520553)
Is that "just" a performance concern though? Ie why is there a base58 and base62 but no base63?

Now you've got me curious on the performance of base58 to base64 hah. Down the rabbit hole i go. Appreciate your reply, thanks :)

Re:Type-safe, K-sortable, globally unique identifier inspire... by kbumsik on Thursday June 29, 2023 @08:48PM (#36529026)
What does “double clickable” mean?
Re:Type-safe, K-sortable, globally unique identifier inspire... by d0mine on Thursday June 29, 2023 @10:28PM (#36529818)
Whether "double click" selects the whole id.
Re:Type-safe, K-sortable, globally unique identifier inspire... by kbumsik on Wednesday June 28, 2023 @08:06PM (#36514557)
> Re: prefix, is the concern that I haven't defined the allowed character set as part of the spec?

It would be great if you add suggestions for compound types (like “article-comment”) in README as OP stated as well.

Re:Type-safe, K-sortable, globally unique identifier inspire... by spoiler on Thursday June 29, 2023 @05:42AM (#36518338)
It seems that's not allowed currently, if I'm reading it right. I'm not sure I like `-` very much. The reason why I don't like it is because of how double-click to select and line breaking works for the dash. Maybe allowing `_` in the typename, and the have the rightmost `_` serve as the separator might be more consistent.

But also, I'm bike-shedding and its only an ID

Re:Type-safe, K-sortable, globally unique identifier inspire... by kbumsik on Thursday June 29, 2023 @09:17AM (#36519947)
I like using "." for this case. Because types definition typically belong to a package or module, which commonly uses "." for separator.
Re:Type-safe, K-sortable, globally unique identifier inspire... by dolmen on Thursday June 29, 2023 @04:55AM (#36518021)
There is no tests.

There is just a single test. Which only tests the decoding of a single known value. No encoding test.

Go has infrastructure for benchmarking and fuzzing. Use it!

Also, you took code from https://github.com/oklog/ulid/blob/main/ulid.go which has "Copyright 2016 The Oklog Authors" but this is not mentionned in your base32.go.

Re:Type-safe, K-sortable, globally unique identifier inspire... by dloreto on Thursday June 29, 2023 @04:00PM (#36525894)
We've now implemented pretty thorough testing: https://github.com/jetpack-io/typeid-go/blob/main/typeid_tes...

Thanks for the feedback!

Re:Type-safe, K-sortable, globally unique identifier inspire... by rtheunissen on Wednesday June 28, 2023 @07:00PM (#36513868)
I'll write some tests for this.
Re:Type-safe, K-sortable, globally unique identifier inspire... by jhoechtl on Thursday June 29, 2023 @04:19AM (#36517796)
I think your misconception is that prefix is sthg. fixed? You decided on the prefix depending on the usage domain.
Re:Type-safe, K-sortable, globally unique identifier inspire... by dloreto on Thursday June 29, 2023 @04:01PM (#36525906)
A follow up:

1. We've now implemented pretty thorough testing: https://github.com/jetpack-io/typeid-go/blob/main/typeid_tes...

2. I clarified the prefix in the spec

Thanks for the feedback!