r/learnjava • • Sep 25 '24

Can someone please explain how versioning works?

I'm not into development yet but I'm the path of becoming one. I am starting to understand how things work in the backend. One thing that is not clear to me is how devs version the components. After a change or bug fix is done, they say it is loaded in version x.y.z I have never created versions in my personal projects. How are these versions created and maintained?

1 Upvotes

9 comments sorted by

•

u/AutoModerator Sep 25 '24

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full - best also formatted as code block

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

9

u/JaleyHoelOsment Sep 25 '24

https://semver.org/ this should answer your questions! or just google “semantic versioning”

-1

u/Ieris19 Sep 25 '24

Either the post has changed or this comment doesn’t even begin to answer OP’s question

5

u/Ieris19 Sep 25 '24

Surprising no one actually answered the question yet.

Usually, a version gets created when you make your code public. If people start using that version of your code, then you can’t exactly go and change it in their system, so we decided to call these “static” code a version, for easy reference when someone has an issue, they can say “I have version 1” and you can reply “It is fixed in version 2”.

As software grows more complex, we needed to get better naming for these versions. So along the years we’ve started a variety of ways of calling code. From a single incremental value, to the most common and widespread now, Semantic Versioning.

In essence, a version of a Software is no different than a Smartphone, you can own an iPhone, but they’re bound to be different if it is an iPhone 5 vs an iPhone 15. It’s just a label to refer to a specific “edition” of your code.

Semantic version or semver is of the form x.y.z although it is important to note it is NOT the only ruleset using that format, it is the most common and its safe to assume everyone uses it unless proven otherwise.

Semver separates updates that fix things but don’t change much (called patches), bigger updates that add features and/or fix things, but are still compatible with older versions (called minor versions) and major versions that break compatibility with older versions. Thus, semver sorts these as major.minor.patch and by increasing a number, all numbers right of that one get reset to 0.

Since major and minor versions occasionally create issues, sometimes patches are ported back to older versions for security. This is usually done through source-control branches in programs like git that allow you to track changes across files and keep several co-existing “up to date” versions of the code in different states. Thus, by switching to a different branch and fixing the issue in an older version, a vulnerability can be patched across multiple versions. This is usually only seen in relatively big projects, or at least, projects with enough attention. Smaller projects tend to suggest you suck it up and update, since there’s not that much demand for back-porting fixes and it can be a lot of work.

Hope this clears up and definitely feel free to look at the resources posted by others. I thought I’d help build the concept from the ground up

1

u/JaleyHoelOsment Sep 26 '24

great answer, thank you!

2

u/hrm Sep 26 '24

I'd like to add a small cautionary statement to all this. Just because a project uses x.y.z they do not have to follow semantic versioning.

Eg. at one point in time the Linux kernel used odd/even minor version numbers to signify if that version was considered unstable or stable. I've seen that in a few other places as well.

Also, what actually constitutes a change worthy of a new major or minor version bump is often debated and some libraries will probably allow some changes without bumping the "proper" version. I mean, lots of bug fixes could probably be seen as incompatible API changes if you wanted to... (Hyrum's Law and all that jazz)

In the end managing dependencies and their versions is a pretty complicated matter and at some point you might very well get screwed over by a "patch" update. Always test the code when doing upgrades.

2

u/nekokattt Sep 25 '24

if it uses semantic versioning, it is a number in the format x.y.z

when you change stuff, you add one to one of the numbers and set the ones to the right of it to zero.

x = major, y = minor, z = micro

  • micro = I fixed something internally

  • minor = I added a new feature but everything else still works

  • major = I broke something existing. If you use my code then you might have to alter yours for it to still work.

Sometimes additional data is put on the end, like 1.2.3+post456 or 1.2.3-beta789 those have additional meanings that are more specific to how each project is managed.

1

u/Ieris19 Sep 25 '24

x.y.z is often but not always semantic versioning.

In the Java world alone, Minecraft is a brilliant example of x.y.z versioning that is NOT semver.

1

u/jlanawalt Sep 26 '24

Like many things, it depends. There are many ways of approaching the issue. The most important thing is recognizing that it is useful, learn about the concept, decide how to implement it, and then being consistent at doing it.

Since this is in learnjava, you may have noticed a lot of jars, especially older ones, have un-versioned file names. Many of those don’t even have version info in their manifest. Learn how to do that and apply it to your code, especially if versions matter.

Look at what your build supports. Some tooling, like Maven, support versioning build artifacts. Work with your tools.