typeid icon indicating copy to clipboard operation
typeid copied to clipboard

RFC: Consider allowing `_` as an additional separator within the typeid prefix

Open loreto opened this issue 1 year ago • 2 comments

The spec, as defined today, only allows for lowercase alphabetic characters in the type prefix. Some users though, might need a way to have a "compound noun" in the prefix. Imagine you want the type to be "user accounts"; today you would have to encode that as a single word useraccounts but it might be preferable to allow a separator to encode it as user_accounts instead.

loreto avatar Jun 29 '23 20:06 loreto

I think a relevant discussion would be: what is the intended purpose of the prefix? Is it merely a tag to differentiate id's for different types? Is it meant to be a human readable descriptor of the type? Or does the spec take no stance on the matter and encourage users to [ab]use the prefix as they see fit?

I personally would tend to use them as tags. IMO 99% of the time having a user_account prefix, as opposed to say ua, is just unnecessary bloat. Wasted space in the database, unnecessary data to send over the wire, hold in app memory, etc. For tags, I think only alpha characters is a fine limitation. If there's a desire to encourage verbosity/readability or flexible usage, then there's a strong argument for allowing arbitrary separators.

mbcrawfo avatar Jun 29 '23 22:06 mbcrawfo

I agree with @loreto . However if the underscore is already use as separator between type and id parts, maybe the hyphen would be better choice.

TenCoKaciStromy avatar Jun 30 '23 12:06 TenCoKaciStromy

maybe the hyphen would be better choice.

A hyphen would break the easy "double-click-to-copy" property of type-ids

conradludgate avatar Jul 06 '23 07:07 conradludgate

Given this specification is inspired by Stripe, why do we differ here when stripe have plenty of examples with more than one underscore?

Stripe prefix list for reference https://gist.github.com/fnky/76f533366f75cf75802c8052b577e2a5

While I agree with some of the above suggestions on how that very specific example could be shortened, I don't think that is great as a universal rule.

What are the implications of supporting this? Why wouldn't we support this?

reecefenwick avatar Aug 06 '23 06:08 reecefenwick

@reecefenwick I'm totally open to supporting an additional _ in the prefix. I started without that support because I think it's easiest to start with the most restrictive spec, and then add features to it, than start with a bunch of features, and if you need to take one back well, now you can't because it'd be backwards incompatible.

Are there any objections to _ as an additional character in a prefix? If not, I could update the spec with the proposal, and we can set a target date/version by which _ would be allowed.

loreto avatar Aug 07 '23 23:08 loreto

Hi all,

Would it be possible to drive this discussion to a conclusion? From what I can tell, there is no technical reason why underscore couldn't be allowed. Therefore, offering this flexibility to users, teams, and companies seems worthwhile.

jonbo372 avatar Apr 04 '24 14:04 jonbo372

We're gonna move forward w/ this proposal. I haven't had time to update the spec and test suite yet. Hoping I can do it this week.

loreto avatar Apr 09 '24 22:04 loreto

Hi everyone, PR with the spec change is here: https://github.com/jetify-com/opensource/pull/306

Please give comments if you're interested in this change before we solidify the spec. Plan is to merge by end of the week. Once merged/accepted, implementations can start upgrading to the v0.3.0 spec that allows for underscores in the type prefix.

loreto avatar Apr 10 '24 18:04 loreto

Spec change is now merged.

@TenCoKaciStromy @cbuctok @firenero @mistermoe @sloanelybutsurely @MMZK1526 @fxlae @softprops @titouancreach @faustbrian @akhundMurad @broothie @conradludgate @johnnynotsolucky @ant8e @guizmaii @Frizlab @nletullier @ongteckwu @tensorush – you have the option to upgrade your implementations of TypeID to match the latest spec. If you do update them, we can change the README to show you're compliant w/ v0.3.0 (as of now, we're listing everyone as compliant w/ v0.2.0).

A few test cases were updated for v0.3.0

loreto avatar Apr 12 '24 17:04 loreto

Closing. RFC approved and officially merged.

loreto avatar Apr 12 '24 17:04 loreto

added support here: https://github.com/conradludgate/type-safe-id/pull/1 will release this version shortly

conradludgate avatar Apr 12 '24 17:04 conradludgate

Updated Haskell support https://github.com/MMZK1526/mmzk-typeid/actions/runs/8739099730

MMZK1526 avatar Apr 19 '24 08:04 MMZK1526

@conradludgate @MMZK1526 would you be able to send me PRs against our opensource repo: https://github.com/jetify-com/opensource/tree/main/typeid/typeid, updating the README table?

Similar to: https://github.com/jetify-com/opensource/pull/314

Much appreciated!

loreto avatar Apr 19 '24 18:04 loreto