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

Natural sorting of indices in PrettyDiff output #20

Closed
mewmew opened this issue Aug 27, 2019 · 0 comments · Fixed by #21
Closed

Natural sorting of indices in PrettyDiff output #20

mewmew opened this issue Aug 27, 2019 · 0 comments · Fixed by #21

Comments

@mewmew
Copy link
Contributor

mewmew commented Aug 27, 2019

Hi @d4l3k,

First off. Thanks for sharing this library! It's exactly what I needed and really does the job well. I think it makes sense to fork a deep pretty-printed, and base the diff on that as you've done with go-spew.

After running messagediff.PrettyDiff on a few data sets, I noticed one aspect that could be improved with regards to the readability of the output. Currently array and slice indices are printed in lexicographic order, whereas natural sorting would make the output more intuitive.

For instance, the current output of messagediff.PrettyDiff is as follows:

modified: [0].Foo = 0x2
modified: [0].Bar = "asdf"
modified: [100].Foo = 0x2
modified: [100].Bar = "asdf"
modified: [101].Foo = 0x2
modified: [101].Bar = "asdf"
modified: [102].Foo = 0x2
modified: [102].Bar = "asdf"
modified: [103].Foo = 0x2
modified: [103].Bar = "asdf"
modified: [104].Foo = 0x2
modified: [104].Bar = "asdf"
modified: [105].Foo = 0x2
modified: [105].Bar = "asdf"
modified: [106].Foo = 0x2
modified: [106].Bar = "asdf"
modified: [107].Foo = 0x2
modified: [107].Bar = "asdf"
modified: [108].Foo = 0x2
modified: [108].Bar = "asdf"
modified: [109].Foo = 0x2
modified: [109].Bar = "asdf"
modified: [10].Foo = 0x2
modified: [10].Bar = "asdf"
modified: [110].Foo = 0x2
modified: [110].Bar = "asdf"

And with natural sorting applied, it would look as follows:

modified: [0].Bar = "asdf"
modified: [0].Foo = 0x2
modified: [10].Bar = "asdf"
modified: [10].Foo = 0x2
modified: [100].Bar = "asdf"
modified: [100].Foo = 0x2
modified: [101].Bar = "asdf"
modified: [101].Foo = 0x2
modified: [102].Bar = "asdf"
modified: [102].Foo = 0x2
modified: [103].Bar = "asdf"
modified: [103].Foo = 0x2
modified: [104].Bar = "asdf"
modified: [104].Foo = 0x2
modified: [105].Bar = "asdf"
modified: [105].Foo = 0x2
modified: [106].Bar = "asdf"
modified: [106].Foo = 0x2
modified: [107].Bar = "asdf"
modified: [107].Foo = 0x2
modified: [108].Bar = "asdf"
modified: [108].Foo = 0x2
modified: [109].Bar = "asdf"
modified: [109].Foo = 0x2
modified: [110].Bar = "asdf"
modified: [110].Foo = 0x2

For natural sorting, feel free to use any library you see fit, or for that matter copy over the implementation from https://github.com/llir/llvm/tree/master/internal/natsort which is based on @fvbommel's natural sorting package. The code is MIT licensed. (any code changes I did are released into the public domain).

Wish you all the best and happy times ahead!

Cheers,
Robin

mewmew added a commit to mewpull/messagediff that referenced this issue Aug 27, 2019
@d4l3k d4l3k closed this as completed in #21 Aug 27, 2019
d4l3k pushed a commit that referenced this issue Aug 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant