r/learnpython • • Jul 20 '24

Will my code still be useable in 2 years??

Hi everyone. I have stored away some python code that I wrote after learning a great deal about python. Iam very proud of my algorithms and I actually used them pretty often but I may have to step away for about 2 years to pursue some other things. Does python code become quickly outdated and unusable if not maintained and updated or will I pretty much be able to pick up where I left off? Basically I'm asking how quickly does the language evolve and the syntax change through time?? Any advice is appreciated.

1 Upvotes

27 comments sorted by

33

u/Sudden-Pineapple-793 Jul 20 '24

You’ll be fine, if you update python or any external libraries, SOME functions might be depreciated, but I doubt it

Just make sure to document your code, you won’t remember what your program does 2 years from now

9

u/Traditional_Soil5753 Jul 20 '24

That makes sense, thank you. So I guess the hardest part is going to be not the code updating but remembering what I was trying to do in my approach to solving the problem with the code. Thank you.

10

u/mokus603 Jul 20 '24

That’s why you comment your code and make a documentation if required.

1

u/oblivic90 Jul 21 '24

Quick tip, if not trivial, document why you did what you did the way you did it, don’t document what your code actually does.

19

u/ahelinski Jul 20 '24

Nope, you need to water it and add processor fertilizer regularly, otherwise it will die.

Jokes aside, as long as your code is not handling request from the web (in that case you should apply security fixes) and the infrastructure stays the same, it can work for many decades.

2

u/Traditional_Soil5753 Jul 20 '24

That's good to hear. I don't know why. I was thinking that within a year or two it would become completely irrelevant. I guess I'm just used to everything updating constantly, but it's good to know that my code will be relevant when I come back thank you.

8

u/Mysterious-Rent7233 Jul 20 '24

Python code written today will probably work with minor updates a decade or two from now.

1

u/Traditional_Soil5753 Jul 20 '24

That's actually incredible. I didn't know any code would be relevant for that long. I was worrying that within a year all of my functions and the syntax I'm used to would be completely outdated. Thanks for letting me know that this is not the case.

4

u/kiochikaeke Jul 21 '24

Code that needs "maintaining" does so cause the ecosystem it interacts with it's constantly changing, for example if you write code that scrappes a specific webpage or communicates through some api or protocol to another computer then if that changes you need to change your code accordingly.

Some things can break if you update libraries and dependencies (or compiler or in this case interpreter itself) however this only really happens between major release versions and usually is not something that absolutely makes it imposible for your code to ever work again.

Backwards compatibility is a very important thing in software so most systems, languages, etc, will try and support old functionality until they can't realistically do it anymore, in this cases most software has LTS (long term support) versions of previous major releases to keep old and important code still working.

Even if all of this fails, you could always just install an older version of the language and libraries you used, any respectable package manager will be able to retrieve those so code several decades old still has a way to work (though that's how you get half of the medical equipment running in windows 98 and I don't think I have to explain why that's a bad idea).

1

u/Mysterious-Rent7233 Jul 20 '24

Look at this file which I randomly selected from the Python standard library:

https://github.com/python/cpython/blame/main/Lib/email/header.py

The median age for a line in that code seems to be about 13 years old.

Same here:

https://github.com/python/cpython/blame/main/Lib/turtledemo/bytedesign.py

And usually they were not forced to upgrade them. They just chose to, to use newer conventions or whatever.

Python 3.0 was released in 2008 and I'd say that 99% of all lines of code from then still work today. The number of full modules that still work is probably lower, but maybe more like 95%, at a guess.

2

u/Traditional_Soil5753 Jul 20 '24

This is incredibly good to know. I was seriously worried that leaving my code alone and stored away for a few years would lead it to just become completely unusable. It's nice to know that this is actually pretty common what I'm doing....thank you.

2

u/UntrustedProcess Jul 20 '24

If you want to encapsulate your code + dependencies to ensure it can run for ages to come, you could aways containerize it using docker or a similar technology.

1

u/Traditional_Soil5753 Jul 20 '24

This sounds useful. Is this a common practice? I've never heard of it.

2

u/Sudden-Pineapple-793 Jul 20 '24

Yes extremely common, docker and kubernates is used by practically every company out there. It lets you run the program regardless of client OS. It bundles all dependencies into an image, which can be ran w docker

5

u/neneodonkor Jul 20 '24

Python is not like NextJS that changes every six months. 🤣 On a serious note, you will be fine. Just leave comments explaining why you wrote what you wrote.

1

u/lemalaisedumoment Jul 20 '24

I recently after five years had to update an old program. It still ran, but the newer operating system did not support the old qt version anymore. I did not have to do anything about the python code, but getting Qt to play nice with python and and RHEL9 was a bit of a hassle.

Python is very stable.

Lets say your code is Python 3.9 compatible without depricated code in it, then it will be python 3.10 compatible too, and likely Python 3.11 compatible and to be honest you will probably even be fine with Python 3.12 and 3.13

1

u/Traditional_Soil5753 Jul 21 '24

I guess that was my biggest concern. Was thinking that the language version itself would update and leave my code irrelevant after about a year or two, but I guess that's not a problem. Thanks for your response.

1

u/lemalaisedumoment Jul 22 '24

https://devguide.python.org/versions/

This by the way is the site with the relevant information about the version schedule. There you can see with the current schedule about once a year a new version is released, and each release receives security updates for 5 years.

But like I said, even most Python 3.6 code still runs on the newest Python version, and if it does not anymore, the parts that got cut in newer versions usually have some information in the online documentation what they are replaced with. Fixes then often are as simple as changing the import statement at the top of the page.

1

u/Traditional_Soil5753 Jul 22 '24

Man, this is good to know. Thank you for posting this. I really appreciate it.

2

u/gdledsan Jul 20 '24 edited Jul 20 '24

I had 4 year old code running, which I refactored last month.

I never touched it during those lost years, and it is pretty bad.

I had to refactor it because I migrated it to a different infra, and while doing that I just took the time to update dependencies, and just give it an uplift.

Bottom line, your code will be usable as long as it is still used, it is not a matter of good or bad, it is a matter of using it.

Look at Salesforce and Atlassian, they have their shitty shit still going.

The only thing you need to think of when deploying your code is to make sure the environment does not change without you checking it works first, this means no updating the language version or the dependencies, no changing the OS either, hell not even the hardware.

This is specially important if you deploy your code automatically, some people add pip upgrades in their CI/CD pipelines, which work for a few months .. until one dependency changes enough to cause some misbehavior or something breaks

1

u/aprg Jul 20 '24

It depends on, well, the dependencies. If you freeze your dependencies it shouldn't be an issue. It can definitely be an issue if you don't manage that.

Last year, I spent a lot of time reading graph neural network papers and playing around with graph neural network libraries as part of my Master's Dissertation; because this is a particularly evolving field of research, even papers that were just two years old had a lot of differences between the implemented version and the up-to-date version of their code base, as there had been serious refactoring in that period in the underlying libraries. Since that refactoring often included significant performance increases, it put me in a bit of a dilemma: if I wanted to play with the better, more optimised algorithms, I had to go around fixing the papers' code.

1

u/Sudden-Pineapple-793 Jul 20 '24

Never heard of Graph neural networks, I’m pretty familiar with all the basic ones, CNN/LSTM/RNN/ transformers. Any good papers to read up about these?

1

u/aprg Jul 20 '24

A Comprehensive Survey on Graph Neural Networks (2019) is probably a good place to start.

This paper is great for actually implemented stuff: ~https://github.com/graphdeeplearning/benchmarking-gnns~

1

u/Jello_Penguin_2956 Jul 21 '24

Yes. Every older version of Python are still available for you. Simply install the same one you use for coding if you want to be sure.

1

u/Jim-Jones Jul 21 '24

With more experience, you're likely to see ways you could have done it better.

1

u/gowithflow192 Jul 21 '24

In two years you won’t even care to look at your code.

0

u/[deleted] Jul 22 '24

[deleted]

1

u/Traditional_Soil5753 Jul 22 '24

I've heard this a lot that eventually I'll find an easier way to do a lot of the things and that my code will become obsolete not to the language itself, but to me.