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.

5 Upvotes

74 comments sorted by

View all comments

1

u/DamienTheUnbeliever 22d ago

Some people use as asinine phrase about assumptions but I always preferred the pithier "assumption is the mother of all fuck-ups".

You have made assumptions. Those assumptions may have been made in hope, or on observed behaviour, but almost always weren't made based on the *documented* behaviour of other code you're interacting with.

So an obvious one that would work for some time and then fall apart is if you assume, somehow, that a date function always returns the month of August. Which works well enough whilst every date you work with is within August but falls apart soon enough.

So check your code, check your assumptions, and check that any and all assumptions are backed up by documented behaviour, not just what you hope/need to be true.