Skip to content

Simpler #11

Closed
Closed
@4kimov

Description

@4kimov

Since the initial library has been out for a few weeks, I got to mess around with it a bit more and realized there are a few rough edges we could iron out:

  1. Lower reserved characters count from 3 to 1 (more data packing into generated IDs)
  2. As a side-effect of number one, min alphabet length can decrease from 5 to 3
  3. Decrease blocklist-related re-generation attempts from almost-unlimited to the length of the alphabet (cc @tzvetkoff)
  4. As a result of number three, re-generated IDs don't have to grow in length (try blocking "SrIu" in the playground to see what I'm talking about)
  5. Also as a result of number three, min length padding is smoother now (cc @joviczarko)
  6. Sounds like minValue and maxValue are not that useful, let's remove? (cc @peterhellberg)
  7. Increase min length limit from alphabet-length to an arbitrary value (1_000 for example)

Pros:

  • Less code; spec (with comments, etc) went from 336 to 301
  • Limited (but still sufficient it seems) number of re-generation attempts, as opposed to currently almost-unlimited / less-predictable
  • Smoother blocklist and min length handling
  • Packing more data into IDs + smaller alphabet allowed

Cons:

  • More dev work for maintainers to re-adjust code (you + me)
  • IDs change, which means users that might have current libs in production would have breaking prod changes (although most of our libs are pre-production version (v0.x) ...so comes with the territory)

Unknowns:

  • Are there any use-cases we don't test for since changing reserved chars from 3 to 1?

Current: https://sqids.org/playground (algorithm code / explanation)
Proposed: https://sqids.org/playground/simpler (algorithm code / explanation)


P.S: Also worth noting that I have no intention of changing the algorithm over and over; I figured this might be cleaner + address some current issues/questions, while we're still technically mostly pre-prod.

Thoughts/feedback?

cc @laserpants @vinkla @niieani @antimon2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions