Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort treats numbers as strings #31

Open
carlocardella opened this issue Jan 9, 2023 · 4 comments
Open

Sort treats numbers as strings #31

carlocardella opened this issue Jan 9, 2023 · 4 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@carlocardella
Copy link
Owner

tt sort numbers as strings

@carlocardella carlocardella added the bug Something isn't working label Jan 9, 2023
@Ste1io
Copy link

Ste1io commented Jan 9, 2023

Given how dicey mixing numeric and lexicographic sorting strategies on mixed strings can be, if you want any input or help testing leading up to release for this just let me know. This is something I deal with on a daily basis and it's the pain in the @$$ with the wrong sorting implementation. Haven't yet found a good solution from other plugins either, so happy to see this show up on the list.

Edit: My use case may be slightly different, actually; dealing with sorting strings that potentially begin with a number, date or time string. I can drop it in a separate issue still if you like.

@carlocardella
Copy link
Owner Author

To clarify, if you have this:

3string
1another
2yetanotherstring

Would you need those sorted by the initial number?

1another
2yetanotherstring
3string

This is my thinking:

  1. If the first word in a line is a number (1 string) sort by number
  2. If the first word is string (even if it begins with a number, e.g. 1string), sort by string
  3. Potentially, but it depends on how complicated it gets, offer an option to choose sort 1string by number, basically extract the number from the beginning of the first word and use that for sorting. I am not convinced this really makes sense but I guess it depends on the use cases

Thanks for the offer to test, I can either share a private vsix here when ready, or publish a pre-release version

@Ste1io
Copy link

Ste1io commented Jan 9, 2023

Close to that, yes, though number 2 could introduce some undesirable results with edge cases involving datetime stamps in universal sortable format and log entries (depends on what ruleset you follow for tokenizing words, and how special characters are treated also I guess).

I’ll be back at PC in the next hour and can give a slightly more specific answer then. I do agree this is best as aseparate sort option, as it increases the complexity of the comparator and in plenty of casual use cases a strictly lexicographer or numeric sort is sufficient anyways.

@carlocardella carlocardella added the enhancement New feature or request label Jan 12, 2023
@Ste1io
Copy link

Ste1io commented Jan 25, 2023

My apologies for the delay in my response; had to replace my i7 SkyLake from ~8 years ago, and the delays set me back a good bit.

During my down time, however, I did have a chance to think through this a little more, and IMHO due to the numerous possible use-case scenarios and parsing "gotchas" (a couple of which you already brought up), this really should be considered as a new feature set with it's own set of sorting rules to chose from - above and beyond what this issue originally addressed.

In the interest of not holding up this specific issue, I'll create a discussion with my thoughts on the additional sorting ideas, which you can convert to an issue at your discretion when something has been fleshed out. I've put together a few notes already, along with some sample string lists representing some of the most common scenarios in my experience which prompted my comment to begin with, which I'll include in the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants