this post was submitted on 07 Sep 2023
34 points (100.0% liked)

Rust

5953 readers
11 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 5 points 1 year ago (2 children)

semver is a nice way to communicate your intent to other humans, but it's never been a great way of programmatically communicating those changes. If you want it to communicate something meaningful programmatically, you'd have to have the version generated automatically, and not rely on a human to do so.

[–] [email protected] 2 points 1 year ago (1 children)

Semver was literally made to communicate programmatically. But people keep using it for "human" communication instead, like the whole "1.0 means stable" thing.

[–] [email protected] 2 points 1 year ago (1 children)

It was made to do so, but failed from the start exactly because humans got involved. semver's ideals can only happen when tooling generates the version number, not humans.

[–] [email protected] 2 points 1 year ago (2 children)

How can a machine decide if something is a patch, minor, or major release? I guess a major release could be defined by a comprehensive unit test suite breaking, but the others are very much something humans should decide.

Imo, the solution is that people need to be less afraid of major release bumps. Do it frequently and it's not likely to cause issues downstream.

[–] [email protected] 5 points 1 year ago (1 children)

It is quite simple conceptually to decide. Simply examine all the functions of the API between two versions. If the signatures are equivalent, increment the patch version. If there are new signatures, but the existing ones are the same, it's a minor version. If any function signatures change, it's a major version.

Then you also need to examine trait impls and such but the basic idea is the same.

[–] [email protected] 4 points 1 year ago (1 children)

That oversimplifies and misses a lot of edge cases, such as:

  • change the meaning of an existing parameter - e.g. an Integer timeout changes from seconds to milliseconds
  • dependency changes, and this package exposes exposes types from that dependency
  • internal refactor changes the order of execution of existing uses (say, a scheduler change in an async library, or event order in a GUI library)

Each of those would be, imo, a breaking change, but an automated semver tool would probably mark them as patch releases. I could come up with more examples, but hopefully the point is clear.

Maybe it's correct 90% of the time, but the last 10% of the time can be really impactful. I think there should be less sigma against major releases. If in doubt, mark it as a major release.

[–] [email protected] 0 points 1 year ago (1 children)

change the meaning of an existing parameter - e.g. an Integer timeout changes from seconds to milliseconds

Ideally you should change the type if you do such a thing, which would cause it to become a breaking change. In this specific instance, you should take std::time::Duration obviously.

dependency changes, and this package exposes exposes types from that dependency

I think that should be automatically detectable?

But yes you're right, in general it's not possible to detect all forms of semver changes. But perhaps at least detecting violations when they weren't meant to be there would be good.

And yea 100% agree with you, people should use the power that is 2.0.0 way more than they currently do.

[–] [email protected] 2 points 1 year ago

Ideally you should change the type if you do such a thing

But that's not always possible or desirable. For example, maybe you're largely just passing it through to another library, and that library made a breaking change.

So I don't think we should have semver always handled automatically, it should instead prompt the developer with its best guess, and the developer would ideally only move from patch -> minor, patch -> major, or minor -> major, and never the other direction. But the developer should always be involved in picking the version. So don't just throw it into CI and call it a day, but instead have a CLI tool that suggests it and requires developer approval before making the PR for the version bump.

[–] [email protected] -1 points 1 year ago (1 children)

@sugar_in_your_tea If you're interested, I recommend looking at how Elm does it. Elm has automatic semver enforcement in its package system.

The long and the short is
missing stuff: major change
new stuff: minor change
patch: internal implementation change.

[–] [email protected] 1 points 1 year ago

I gave a more thorough response with examples to the other user that replied (link on my instance here, but basically there are cases where you could break someone's code with a patch release.

I'm completely fine with using tools to help decide what versions to assign, but in general developers should not hesitate to increment the major version if there's any doubt.

[–] [email protected] 1 points 1 year ago (1 children)

Is that even possible though? Sometimes you need a human to understand if something is a breaking change.

Imagine an API like fn third_planet_from_sun() -> String, and an update is made where the output changes the value to be lowercase instead of capitalized. That should normally be considered a breaking change.

However, imagine fn current_version() -> String. That is by its definition meant to change outputs between versions, so it isn't a breaking change since that's part of its human, documentation based API contract.

Also, what if somw function which returns a String changes, but only one code path that is very hard to hit changes the output? How would a machine find that?

I guess the first example with Earth / version could use some attribute macro so devs can say the output is expected to change across versions, but then there is no way for a program to know what is a breaking change vs expected vs a bug.

[–] [email protected] 1 points 1 year ago

To do it 100% probably isn't possible, something something halting problem. However, you'd catch a lot of basic mistakes with proper typing. In your example, the first function should be typed like this: fn third_planet_from_sun() -> Planet, where Planet is an enum. De/serializing it still has the same problem of interpreting an arbitrary string, but at least for deserializing it, you can be loose in what you allow and just lowercase it before matching it to the enum.