Why not both
I did both of these at once last week.
Added a breakpoint. Debugger didn’t break.
Added an
echo "here";
. Debugger didn’t print.Added a
throw new Exception('fuck');
. Debugger didn’t throw.Stepped through. Debugger wouldn’t let me step in.
It took me almost an hour to realize it wasn’t the debugger’s fault and that a variable I thought was guaranteed to be truthy at that point was actually falsey due to upstream changes in a spreadsheet parser. I felt kind of stupid for not trusting the debugger at that point.
This meme makes it look like it’s hard decision. I always immediately slam the button on the right.
Kind of unrelated, why does c sometimes fail to print if it hits a breakpoint right after a print while debugging? Or if it segfaults right after too iirc
“Fine! I’ll set up debugging! Stupid piece of…” - Me at some point, a little to late, into most projects
Honestly, before I’m done setting up a debugger and creating breakpoints, etc. I have added 10
consle.log()
at assumed failure points and run the code again two times.For local development, it should be super quick. However, I’m currently building a small project where a device (or rather the library using it) can’t really be used with a debugger. So 500 print()s it is.
I had tried to use debugger with React so many times and each time I’d drop it soon after. Not useful at all.
Does much better job on the backend though
but it’s so much easier to put in
echo "if you can see this it worked"
100 times in your source. lolI’ve noticed that debugging tends to be more important in imperative languages than functional ones. With imperative style, you have a lot of implicit state that you need to know to figure out what actually happened. So, you end up having to go through the steps of building that state up before you can start figuring out what went wrong. On the other hand, the state is passed around explicitly with the functional paradigm, and you can typically figure out the problem by looking at the exact spot where the error occurred.
My typical debugging workflow with Clojure is to just read the stack trace, go to the last function in it, and then see what it’s doing wrong. Very rarely do I find the need to start digging deeper. I think another aspect of it is having an interactive development workflow. When you’re running code as you’re developing it, you see problems pop up as you go and you can fix them before you move to the next step. This way you don’t end up in situations where you wrote a whole bunch of code that you haven’t run, and now you’re not sure if it all works the way you expected.
With imperative style, you have a lot of implicit state that you need to know to figure out what actually happened. So, you end up having to go through the steps of building that state up before you can start figuring out what went wrong.
i think i struggle with this part the most since i’m entirely self taught and relied on very old methods for writing my source since the educational material i used was the most common and freely available at the time i starting doing development work. i’ve learned that it was acceptably sufficient for the IT-based problems that i was trying to solve at the time i learned it and that legacy style has been keeping me at a disadvantage.
if seen some of the newer style of debugging like the one you’re shared from the young fresh graduate developers who are lucky enough to be spared the slog of a over decade within “customer service” oriented side of the tech industry umbrella and it’s painfully evident to me how vastly superior it is compared to the old methods that i taught myself and it’s encouraged me to seek a degree to help me master them and my new job will make that degree free for me; which matters A LOT as an american considering the price tag it entails.
I find a good approach to getting better at programming is to reflect on the projects you’ve done and try to identify patterns that got you into trouble. Then you can try doing things differently next time, and eventually you end up settling on a style that works for you. At the end of the day it’s really just practice. The one key thing I’ve learned to focus on is reducing the operating context I need to have when reading the code. Once the context becomes too big to keep in your head, then trouble starts. So breaking things up aggressively into small components you can reason about in isolation tends to be the best way to write reliable code you can maintain over time.
Surely we all write unit tests and debug from there, right?
… Right?
Depending on what kind of coding you’re doing, there might not be an obvious, really atomic unit to test. Most people here seem to do the data-plumbing-for-corporations kind, though.
Especially then I’d test the shit out of everything? I’m getting paid for writing correct software.
data-plumbing-for-corporations tends to be able to be done in a way that’s easily testable, but also most people get paid to bolt on new shit onto old shit and spending time on “done” code is discouraged so once they fall behind on writing tests while developing the new shit those tests will never be written.
and bad developers that won’t write tests no matter what actually do exist.
If I actually did have that kind of job, the tests-first philosophy would sound very appealing. Actually, build the stack so you don’t have a choice - the real code should just be an instantiation of plumbing on generic variables with certain expected statistical properties. You can do that when correctly processing unpredictable but repetitive stuff is the name of the game, and I expect someone does.
At a certain level of detail, tests just become a debugger, right?
I’m thinking of something like an implementation of Strassen’s algorithm. It’s all arithmetic; you can’t really check for macro correctness without doing a similar kind of arithmetic yourself, which is basically just writing the same code again. It resembles nothing other than itself.
On projects where I had to write tests, I wrote them to pass the current code.
I miss having a functioning debugger after moving to helix/neovim
I’ve had no issue with the debuggers available in meovim. A bit hard to set up dap and dap ui but once it’s there it’s golden
I couldn’t get it working in neovim a while back and now have moved to helix which kinda has it but not really
Get to my level of guts feeling debugging
Debug single threaded code, log multi threaded code.
“Oh, they print in that order? That’s weird.”