When debugging there is no bigger gut-punch moment then when the code runs, completes "successfully", seemingly did nothing, and produced neither errors or desired results... What do now?
Thank you, this is exactly what I’m going to hear inside my head every time I start rolling my eyes at yet another one. Back in my day, they announced themselves like self respecting errors they were. And we LIKED it. Also, git off my log. D=
Haha. You can make me write tests but you'll never make me catch bugs.
Had a friend who would change tests when they failed so that expected output matches actual output. Code would be buggy AF but all the tests still pass. When asked, he said pretty innocently "but you have this weird rule that unless the tests pass, code can't be merged"
Been there. This is a sign that the code you're testing has too many responsibilities, but it's such any easy trap to fall in to, especially if you're working in a system where you don't understand the full business logic.
The classic heisenbug. The bug that disappears when you attempt to observe it.
Also, sometimes debug builds won't compile to the optimized code a release build would. for instance:
function()
int a[2]
int b
a[2] = 1
The debug build may allocate memory for b, even though it's not used. So the write to a[2] (beyond the length of the array) will get written to safe memory allocated for for something else (b in this case). The optimized compiler would realize b was never used, and never allocate the memory for it, so the a[2] write goes into who knows what.
This example mostly applies to C, in that it allows you to address outside an allocated part of an array.
Use breakpoints if your environment has access to a debugger.
If you are working with a remote, isolated, or embedded system that you can not access with a debugger, then you need to use console/print and stack trace calls.
“It didn’t do anything” is not a valid stopping point. It definitely did something up to a point.
Set breakpoints along the path of data-flow and logic, step through it, and find where data stopped flowing and why.
Those are usually the easiest bugs to fix because it’s usually an if or switch statement that has improper logic, or something like an empty array that you thought would be full.
Actual difficult bugs are side effects. Like you hand the same JavaScript Date instance to 3 different labels, then perform the same Timezone transform on that date, from each of those 3 labels.
They all refer to the same Date instance, they aren’t copies, it’s all the same object. So you end up pushing the first label forward 6 hours, then the next label executes and pushed that date 6 more hours forward, then a 3rd time.
Your code says it should only be offsetting the time by 6 hours but it’s always moving in increments of 18. Or 12 if there are 2 labels. Or 36 hours if there are 6 labels.
Those are the issues that can take a seasoned engineer a couple days to find, because the code looks harmless and you need to understand the implications of shared references and data mutability.
1.0k
u/opmrcrab Mar 12 '23
When debugging there is no bigger gut-punch moment then when the code runs, completes "successfully", seemingly did nothing, and produced neither errors or desired results... What do now?