23
jschmold
69d

TL;DR: Learn, trust, and use your debugger.

Today I learned a valuable lesson I had 100% forgotten as a result of doing JS development for so long.

Debuggers are a programmer's best friend.

It's logical in JS to do a quick console.log, save, and reload to see how things work. I haven't used a debugger since I did C# dev easily over a year ago.

I'm now developing a game of mine in C++, and HO MAN was I wrong about debugging using logging. Sent me on a 2 hour wild goose chase.

Rewind:

I wrote the first test of the first file in this project, and it is tossing a "double free or corruption" error every time. Confused the hell out of me, because I don't know how on earth this could even be possible.

Run Valgrind, all is green. k. Why is there no double-free error when I run Valgrind?

I do logging, and it indicates a function unrelated to the actual problem. Two hours of me experimenting, I get fed up and decide to
-DCMAKE_BUILD_TYPE=Debug, run gdb, and give 'er shit.

The function I thought it was? Perfectly fine. No errors, no bugs, runs great. Next 5 lines, no errors. Program exit, BAM. Error.

I know perfectly well what happens to objects on the stack when a scope-block breaks, so I look into the destructor of the class, and go line-by-line there, where I find it.

I was do a while loop, seeing using std::queue's queue::front function and checking if it returns nullptr. TURNS OUT, that's not what you should do. So instead, I iterate up from 0 to the queue::size, and it works just fine.

Fuck me, right? Haha, well, lesson learned. Trust thy debugger.

Comments
  • 10
    Can confirm. This bad boy here helped me get rid of the bugs way too many time I lost count
  • 2
    @PythonTryHard electric debugger?
  • 2
    Aren't you supposed to compare ::front() to ::end() instead of null? All iterators work like that.
  • 0
    I always thought that programmer best friend is coffee 🤔
  • 1
    @irene Yep, compatible with any language available
  • 0
    @irene
    If you are, it's not something I've yet learned. I haven't picked up all the best practices yet 😛
  • 0
    @jschmold it's not a best practice but how iterators work 🤷
  • 0
    Wouldn't you use the debugger from dev tools while coding js?
  • 1
    @Futezatorul
    Probably a good idea in the future, but I generally don't have "What the hell, why?" moments in my web dev in the last year. I can usually pinpoint the exact thing that happened and when, so I've never needed to use the debugger on that front
Your Job Suck?
Get a Better Job
Add Comment