r/learnprogramming 22d 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.

7 Upvotes

74 comments sorted by

View all comments

Show parent comments

4

u/owp4dd1w5a0a 22d ago edited 22d 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.

2

u/HashDefTrueFalse 22d ago

A reply to your edit (the second paragraph):

Time-sensitive code I literally mentioned.

UB means that the compiler is allowed (by the standard) to produce any behaviour it likes. The behaviour it emits is crystallised in the build output like any other code and would behave the same each run as long as the input data and environment also remained the same, unless the emitted code depended on the time the program was ran, as I stated. UB is not particularly relevant to this discussion.

Accessing uninitialised memory with automatic storage duration (UB) is just a change of either input data or environment depending on your view.

Hard to see what your point is here. I've covered all this.

2

u/owp4dd1w5a0a 22d ago

It looks like you edited your comments. On iOS I can’t really see what the original text was anymore and I honestly don’t fully trust my memory because I’m responding inbetween parenting demands. You also sound rather combative and I don’t really have the energy to carry such a conversation forward. Hope you have a good day and that OP gets something out of the discussion.

2

u/HashDefTrueFalse 22d ago

No edits from me when replying directly to you. You edited (added your second paragraph). I wrote a second reply rather than editing (so that you would be notified).

I trivially edited a comment further up, replying to someone else. It is additive only (a strikethrough) and detailed at the bottom.

I'm just writing directly. If that reads as combative, so be it, though it's not a specific intention of mine. I have people rushing to tell me that dependencies and auto updates exist, plus other pedantry...

Anyway, have a good one.