Hacker News new | past | comments | ask | show | jobs | submit login

I don’t like semantic versioning because it’s difficult to sort. E.g. 1.2 is more than 1.100, and that doesn’t even include fix versions.

Has there been a better proposal to semantic tags which makes organizing and sorting them easier?




In fact there are standard-ish sorting methods that work fine with mixed text and version numbers such that 1.100 is more than 1.2, and v1.100 is more than v1.2.

Git has built in version sort, though it's not the default. GitHub shows tags in version sort order in the drop-down tag selection.

Here are some commands that use that sort order:

  ls -v                               # Linux only.

  ls | sort -V                        # Most modern OSes.

  git tag | sort -V                   # Git tags in version order.

  git tag --sort=v:refname            # Same as above, it's a git builtin.

  git config tag.sort v:refname       # Set default sort order for `git tag`.

  git config versionsort.suffix -pre  # Make 1.2-pre1 sort before 1.2.

  git config versionsort.suffix -rc   # Now 1.2-pre1 < 1.2-rc1 < 1.2 < 1.2-patch1


There’s even a GNU C Library function: strverscmp():

https://www.gnu.org/software/libc/manual/html_node/String_00...


git directly uses that function :)

(... well, it's copied and pasted into the tree but close enough)


It's not semantic versioning, but a project I am on started using calendar versioning[1]. I was hesitant to try it at first, but it's kind of growing on me. It's really easy to organize and sort. We have a pretty regular release cadence so it was easy to implement, but I could see it being more complicated for certain projects.

[1]: https://calver.org/


I think calver is good for things that don't really have an API per se. Stuff like GUI applications.


Ancient Perl started off encoding their version numbers as a float (you can see it in their old version numbers before 5.6.0, 5.005 for instance[1]). Integers were the major version, thousandths were minor, and millionths were patch. So 1.003004 was 1.3.4. This makes them extremely easy to sort. At some point they decided that was too obscure and came up with "version strings". But the old way is (crazily) still supported and can cause pain if you forget since 1.2.0 is unambiguous, but 1.2 means 1.200000, ie 1.200.0.

[1] https://en.wikipedia.org/wiki/Perl_5_version_history

Just to be clear, I don't actually think this is a great solution, but is _is_ easy to sort.


Perl still represents versions like that internally, the "pretty" v-prefixed variant is just some overload/OO magic.


Sort in which context? Unix has `sort -V`. Of the other languages I use, they all have either built-in functionalities, or small libraries to do it.


That's a good point. With the omnipresence of semver, you'd think that more interfaces would support sorting tags with a semver comparison instead of lexically.

I searched for a bit and found that github does this ( e.g. https://github.com/TryGhost/Ghost/tags ). Also there is a git config that sets this globally for the git cli: `git config --global tag.sort version:refname` ( found here: https://gist.github.com/loisaidasam/b1e6879f3deb495c22cc ). That's another git config going onto every machine I use...


Semantic versions can't be sorted trivially, it's true. For projects that benefit from the "semantic" part of semantic versioning the benefits outweigh that minor inconvenience. But not everything needs semantic versioning.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: