Improve the algorithm for satisfying the min length #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #6
I was told that if I came up with an "elegant fix (meaning does not increase complexity of code and has clear benefits)" I could make a PR.
The benefits that this change offers:
The only "con" of this approach (or you could say its "cost"), is one additional reserved character. But I think the advantages justify that.
This also does NOT suffer from the "accidentally appending a blocked substring" problem which you alluded to in this comment, because if the junk characters that the min length algorithm adds either happen to be a blocked word themselves, or happen to form a blocked word when prepended to the rest of the ID, the
if (this.isBlockedId(id))
block right after it would take care of that, by adding a throwaway number and re-encoding. So that's a problem that's elegantly and almost "automatically" solved, so to speak.From a more "theoretical" PoV, you could also argue that the previous technique of adding throwaway numbers is more suited to avoiding blocked words (since it causes the entire ID to change), but is a bit too "radical" as a way of just satisfying the min-length, whereas surgically adding junk characters (like this PR is doing) is more appropriate as the min-length algo.
Again, no tests yet to first get feedback on the change itself.