i wrote a class of about 500 lines, it involved a two dimensional array. I had this section where i went through the array with 2 for-s and i wrote
1 2 3
for ( int i = 0 ; i < NMAX ; i++ )
for ( int j = 0 ; i < NMAX ; j++ )
instead of j < NMAX , of course ....
I spent like 2 hours trying to fix it, no success ... I ended up rewriting the class and fixing the error in the first program in about 10 minutes after rewriting everything. Now that was fun !
I wrote a huge and fast linked list class, it worked fine until it reached a certain size of about 10K nodes when i was using it for some app..
Spent half my weekend removing a semicolon.
Edit:
I'm now formatting a bunch of arrays (fonts and images) that are hundreds of lines long because the guy that wrote the program originally didn't bother to, and my text editor (gedit) doesn't handle long lines very well (because it has to break them apart, and thousands of characters is too much for it). So, I decided to use Code::Blocks' editor for breaking up the lines and gedit to format them because gedit has a decent find/replace function, whereas Code::Blocks' is severely lacking (it can't handle escaped characters).
I then have to split a file that is about 10 kLOC into different files because the same guy put the entire program in one file. The guy who maintains the program now added some more files (funnily enough, the ones he added are ones that don't need re-writing/re-organizing) but I want to split it up properly and edit some of the code (it's a real mess so I want to fix it; mostly re-formatting parts of it and maybe removing some code). The program's also pretty buggy, so I'm going to go around fixing all the compiler warnings it generates and see if I can fix some of the bugs.
Edit 2:
Day 2 and I've now split the files up properly, with separate modules and everything. In total there is just under 17kLOC which I need to fix because my splitting operation has created a large number of broken dependancies (includes missing, etc.). At the moment I'm formatting each file.
I once spent a week trying to make this image appear on the screen in a C++ program, I just coudn't figure out how it was not working. I even asked for help on StackOverflow.com and this forum. Then I rebuilt it, and it worked...
You may have seen, I have spent over a MONTH debugging a particular problem in which I thought the content of my structs was flipping, but really I had done a no no and it turned out that I had made code that had assumed parameters to be read from left to right... when instead, the parameters were being read right to left. A MONTH trying to debug something I had never thought would even matter... sure teaches me!!
Dear god. I just went through hell and so I feel that I have the right to bring this thread back.
While developing my terrain generation application, a random bug popped up. I don't remember at which point it started to pop up, I tried to figure out what it was but to no avail. There wasn't anything specifically that seemed to trigger it, and I could sometimes get a debugging session where I could add up to 15 displacement levels before crashing, so I decided to just continue developing my algorithms without worrying about the crashes.
After a while the crashes got on my nerves. I've spent the past 2 weeks debugging it. Finally, an optimal occurrence showing exactly at what line the problem was (prior it had shown the disassembly, and call stacks were uselessly pointing to SFML), it was accessing an array. Rather than simply restarting the session, I decided to look at the global variables. One of them seemed to be going higher than it was meant to. Want to know what the problem was?
My day was when i spend all the day to , 25 consecutive hours struggling with the dumb php(with css, html ) code and after that i felt like the shi* you know....
From my personal experience, asinine bugs are usually caused by code buried too deep in a lot of twisted logic or using features of a language/library without fully understanding what the implementer intended.
Usually, these types can be alleviated by using TDD (test-driven development) judiciously. Doing so can save a boatload of time, overall, and result in more robust software, by catching and localizing bugs early. I used to just use TDD once in a while, but now, I use it more and more, and I've also integrated valgrind's memcheck and drdcheck (helgrindcheck) into my builds.
Aha... test-driven development where you write test first before coding. Last time there was model-driven where you model the business problem domain first before coding, extreme programming etc etc methodologies.
YMMV, but TDD is a huge time-saver for me. Spending less time in gdb is a good thing.
Part of what makes programming hard is entropy - from a randomness perspective, there are many more ways for your program to be wrong/buggy than correct. Most programming languages have plenty of degrees of freedom for you to shoot yourself in the foot. That means when I get lazy and copy-paste-code (as I see in some of the examples above), etc..., I could get burned if I forget to edit. To counter this, TDD ensures that at the very least, the function is outputting something reasonable. Overall, I find the extra work to be worth it.
Trying to find an error in our Project for 3 weeks. Tested each component having 1000s of lines of code, only to find out in the end that the error was done by a team member in a function, which was being invoked repeatedly!!
1 2 3 4 5 6
void myfunc()
{
staticint a;
a = 0; //Damn
a++;
}
Reason: Project Coding guidelines state each variable should be initialized before being used!
Sorry to revive an old topic, but what was the problem with that code? It looks fine to me, apart from the fact it doesn't do anything.
This was an example of the situation that was being used. Rather than copy and paste the whole thing, they just posted an example of it. The problem was that a would always be 0 when it was meant to be incremented at each call:
Spent 3 months looking for a memory leak in a Java server that I ended up simply scrapping in the end and rewriting in C++.
So...that was my least productive 3 months ever.
*The JVM was putting the session data into the old generation and was not being collected, and when they were collected, the full on GC would run and freeze the server for ~3 seconds.
Even with the magic of running a search, there are still instances where you don't cover all the scenarios and miss something. There is also chances when you unintentionally change something and your program is relegated to a worse state than before.
@helios
I think, suffice it to say, semicolons are ubiquitous as the bane of a programmer. However, having programmed for couple of years now, I know this is usually the one place I should check but I think beginners experience this alot.
Sorry for the confusion. It wasn't meant as a direct response to you rather I was replying to your post. Sorry. I know you didn't mention semicolons. I was just replying to the original poster's poster; your post. :)