One aspect I feel is never talked about is that setting up the debugging more often than not takes you out of the mental space of the problem you are trying to solve. A console log is basically there already in many cases.
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.
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.
Tests first is only good in theory.
Unit tests typically test rather fine grained, but coming up with the structure of the grain is 80% of the work. Often enough you end up with code that’s structured differently than initially thought, because it turns out that this one class needs to be wrapped, and this annotation doesn’t play nice with the other one when used on the same class, etc etc.
This meme makes it look like it’s hard decision. I always immediately slam the button on the right.
Why? In my experience using a real debugger is always the superior choice. The only time I don’t is when I can’t.
I rarely have access to one.