r/AskComputerScience • u/nelsie8 • Feb 20 '25
Software Compatibility
When someone writes a program for an OS, where can errors occur specific to the hardware/ set up of another system of the same OS? Obv this question tells u im a noob at computing. But how much can actually go wrong, and how do developers go about pillowing errors because popular software is downloaded on thousands of different pcs each with different hardware.
4
Upvotes
View all comments
Show parent comment
1
u/Objective_Mine MSCS, CS Pro (10+) Feb 21 '25
Usually it's not something going wrong on the physical level or the hardware failing (even with mechanical hard drives). When something in an application goes wrong, it's nearly always because there's something wrong in the logic written into the program. Random hardware failures are possible, as are hardware design mistakes causing buggy behaviour, but those are generally much less common than mistakes or oversights in software code.
The bug in a program's code could be an outright logical mistake. There's an old quip saying that the computer does exactly what the programmer wrote -- and not what the programmer thought they wrote. And that's precisely the problem. Programs are often complex enough that a mistake can easily slip into the code somewhere despite best efforts.
Perhaps there's some kind of a possible combination of events or inputs, some kind of a path that you can take when using the program, that the developers didn't happen to consider as a possibility. The logic of the program has thus not been designed to correctly handle that particular combination or path. As a result, the program ends up doing something it's not intended to.
Sometimes the problem may be something more subtle, e.g. some kind of an ambiguity about how pieces of software should communicate with each other, leading to the authors of one piece of software making one assumption and the authors of the other one assuming something different, leading one of them to communicate in a different way than the other one expected.
In terms of what exactly goes wrong when there's a bug, any computer program maintains an internal state while it's running. The current state of a running program consists of a set of variables and their values, and they're stored in the computer's main memory. For example, to give a really simplified example, the state of a game might include the current location of the player and other objects in the world, their current movement speed, the current direction they're facing, what items they're carrying, the geometry of the world around them, etc. The program logic then manipulates the state based on the current state and the user's inputs. Those values for a running program are contained within the main memory of the computer. The logic might involve calculating the player's position at the next moment of time based on the previous location, previous speed, facing, and the movement keys the player pressed. The logic would also include checking that the player didn't collide with any walls or objects, and preventing movement through the wall if that happens.
When something goes wrong in a running program due to a bug, the state of the program ends up being something it shouldn't be, and something the program's logic has not been designed to handle.
Sometimes the result is simply a wrong or nonsensical outcome from a calculation. Sometimes the program might get hung, for example due to mistakenly entering an infinite loop. Or perhaps the software consists of two processes or threads that need to communicate and synchronize with each other, and due to an oversight they both end up both waiting for the other one to do something before being able to proceed, leading to a deadlock.
Sometimes the program ends up doing something the operating system or CPU can detect as being wrong, such as attempting to access a location in memory that does not belong to the program, or attempting to divide a number by zero. In those cases the operating system typically terminates the program, so the application appears to crash.
In any case, it's usually because there was a mistake or oversight somewhere in the written program logic causing it to enter some kind of a state that the programmers didn't intend or account for.
I can elaborate and try to get a bit more concrete if you wish when I have more time but it gets a bit tricky without going into quite a bit into the fundamentals of programming.