Description
SemanticVersion
is a data type for representing version numbers.
It's used in the compiler to implement the compare_versions
macro, which in turn is used to adapt C bindings depending on the library version.
The implementation of SemanticVersion
and compare_versions
is solid. But the design is problematic. It's only targeting version numbers conforming to semver
(major.minor.patch-pre
). semver
is a popular versioning system, but far from the only one. The reality shows a great variety of software version schemes employed in the wild.
For the implementation of SemanticVersion
, a great number of current software versions can be considered compatible to semver, even if it doesn't actually follow semver, but has a similar format. But as soon as the format doesn't match up, SemanticVersion
and compare_versions
can't handle a version (such as 1.0
for example). For a general-purpose implementation, this is unacceptable. It should support a wide variety of version number formats.
SemanticVersion
is therefore pretty much unusable for anything, unless all versions it needs to handle are guaranteed to conform to semver. In any real-world application, with versions coming from different vendors, this is very unlikely. shards
for example uses a custom implementation for comparing version numbers that is more flexible.
Ruby has Gem::Version
which is very versatile. I have a Crystal version of that type with a similar interface but a different internal implementation which should be more efficient and could even be further improved for comparison performance.
I think it could be used as a drop-in replacement of SemanticVersion
and renamed to SoftwareVersion
. It's available here: https://gist.github.com/straight-shoota/d8eec4a346018b0a51c1730b2a5c2bf8
I could also consider publishing it as a shard, but I think it would also fit in the stdlib and would improve compare_versions
as well.
Activity