4 ms·
Let's see what happens next when you debug via logging : When you actually have an exception and you put a `console.log(some_var);` in your code and then you r
by drinchev 11y ago
Let's see what happens next when you debug via logging :
When you actually have an exception and you put a `console.log(some_var);` in your code and then you reach it. Your next step is usually to fix your code and run it again. This time you see the corrected value in your log. Easy fix.
If the problem, though, is caused by some other part of the code, then you need to move the `console.log` statement up in your callers' functions until you see where the problem is. That sucks.
Now let's see what happens when you use a debugger :
When you reach that point, you check your variable, see that there is something wrong with it, check the caller, step inside the caller and manipulate the code, until you see everything is where it is supposed to be. One shot ( run ) fixes all.
Now straight to the point :
> Are you sure it helps more than console logging?
Until you get used to the debugger, you will ask yourself this question. Console logging is bad for recursive functions, loops, huge variables, etc. How many times have you write : `console.log(var);` and then one run later `console.log(var['some property'])` and even go deep?
> Would you be able to debug something without these tools?
Sure :) Sometimes I don't use it at all. e.g. when I'm doing a quick thing and use Sublime Text instead of WebStorm.
> Do you think potentially these tools abstract some of the work away from you?
I haven't run any benchmarks. Maybe I'm a bit slower with a debugger for 90% of the exceptions, but there is always an exception, hard to be console.logged, that compensates all that time.
- philbo 11y ago> Until you get used to the debugger, you will ask yourself this question. As a counterpoint to this, I was pretty much exclusively a debugger guy for the first 10-12 years of my career. Now I'm pretty much exclusively a logging kind of guy. Familiarity with a debugger has nothing to do with it. > Console logging is bad for recursive functions, loops, huge variables, etc. And debuggers are bad for focus/blur event handlers in UI code because they change the focus state of the thing you're trying to debug. Ultimately, neither of them is perfect, not all problems are alike, one is not an objectively better tool than the other. They both have merits.
- busterarm 11y agoI'm sorta middle of the road. I have a strong preference for having a debugger so I can set break points and testing assumptions in a REPL at that point in the code though. I'd say it's pretty much required to do PHP (and especially Wordpress). On that note, WP Core team, would it kill you to extend some basic array functions to WP_Query objects?
- Terr_ 11y agoI think the print/logging tactic get a little bit of a bad-reputation mainly because of the minority out there who do it because it's the only approach they know how to take.