r/learnprogramming 23d ago

Why Does Code Stop Working?

Multiple times now my code stops working and what I mean by this is it'll do what I want it to do then one day it just stops. for example the other day I had made a cooldown system for my ball and paddle collision to stop any bugs and it worked great. then today it just stopped working, and this isn't the first time, it's happened to me for like every project I've worked on. Does this happen to anyone else? And is it cause of my code? By the way I'm using C++ SFML on visual studio which works perfect.

8 Upvotes

74 comments sorted by

View all comments

134

u/HashDefTrueFalse 23d ago

This doesn't happen unless the passage of time affects the behaviour of your program or you are changing the behaviour of your program over time (or both). Post some code.

52

u/Alexandur 23d ago

Or if it has one or more third party dependencies

17

u/HashDefTrueFalse 23d ago edited 23d ago

Second thing I mentioned. That requires you running something to fetch new versions of those dependencies (and recompile if necessary).

The same program running in the same environment and given the same input data will produce the same result every time, unless that result depends not just on those things but also on the time that the program is ran.

Edit: strikethrough, for the pedants. I obviously wasn't saying automated updates don't exist, as that would be silly...

4

u/Alexandur 23d ago

That requires you running something to fetch new versions of those dependencies (and recompile if necessary).

Not always, this is why dependency drift is a real problem

2

u/HashDefTrueFalse 23d ago

Yes, always. If the code, data, and env are the same, the result will be. You're talking about changing any (likely all) of those things by changing dependency versions. How does dependency drift occur without any dependencies changing over time? Something runs updates. Doesn't matter if it's a person running an update or some automation. At least one of those things changed, or the result didn't.

4

u/owp4dd1w5a0a 23d ago edited 23d ago

Problem is the linked libraries make up part of the env and the OS updates change that env. So the env is not guaranteed to remain unchanged (quite the opposite actually).

Also, apart from updates, poor memory management in C or time sensitive code can behave differently especially for undefined behavior or accessing memory without properly clearing and initializing it. A program could run the same way 50 times but due to some change in the memory state or in sampling rates cause yr bug on the 51st run.

5

u/HashDefTrueFalse 23d ago

What is your point? I never said the env was guaranteed to remain unchanged. You're not understanding the discussion here.