Live data from Hacker News

Use console.log() like a pro (2020)

markodenic.com

151–156 of 156 posts

Re: Use console.log() like a pro (2020)

#151
post #28

I've put over 200 tips like that on my website: https://umaar.com/dev-tips/ Each tip has a textual explanation, and an animated gif if you're a visual learner (I know, I need to scrap gifs and move to regular videos). There's a lot of tricks there which can hopefully improve your development and debugging workflows. Let me know if there are specific things you'd like to see. A few people have asked for how to find me…

Great thing! Do you support rss feeds, so that I can stay up-to-date?

Re: Use console.log() like a pro (2020)

#152
post #136

Earlier quoted context omitted.

FWIW, it's not like it could work in any other way. When you console.log() an object, it just stores a pointer to the object, and decorates it with an interactive label containing some text, so that it looks nice. This is fast to do, and most of the time, it's exactly what you want. To log a static snapshot with equivalent interactive expansion capability, console.log() would have to do a general deep copy of your ob…

> To log a static snapshot with equivalent interactive expansion capability, console.log() would have to do a general deep copy of your object Not necessarily, and if it did I don't think it would address the actual problem. console.log could do all the presentation work upfront, right then and there when you log, and provide a collapsed view of that. This would have to include detecting and cycling handles, as it wo…

Technically it's V8/DOM CDP devtools JS -> devtools DOM -> Skia displaylist.

In the current status quo, devtools requests values through CDP as you expand the nodes.

Based on experiences with using Expand recursively on surprisingly short JSON network responses, I get the impression either the CDP I/O or the JS driving it is quite slow. Or the implementation's just accidentally quadratic.

In any case, I get the impression the right solution would be to make V8 execute and retain the deep-copy internally, then forward bits of it over CDP as requested.

Hrm, now I'm curious if the underlying mechanics that power the HeapProfiler could be readily repurposed for this.

The only fundamental issue, which is likely been the central blocker all along, is representing objects that are cyclic; the implementation would be closer to "object snapshot" than "literal deep copy".

(CDP = chrome devtools protocol, ie what gets exposed over --remote-debugging-port.)

Re: Use console.log() like a pro (2020)

#154

Earlier quoted context omitted.

Browser debuggers are amazing. I've been using them since Venkman. There's no substitute for setting a breakpoint, via the UI or a `debugger` statement, and watching your code execute a line at a time, in context. But that doesn't make console.log() a bad practice! The console is a great tool I am glad to have, especially when I remember the alternative, which was calling alert() and getting [object Object] and wanti…

Use console.log for it's intended use, formatting string output, but for debugging purposes, it is a bad practice because the reason it's used usually do not usually justify the sloppy unfocused mess it leaves behind. A poorly written log statement is tech debt, as well. Debugger provides all the benefits one would expect with console.log usage: 1. You can see where you are at that moment of execution in code 2. You…

What about your workflow causes console.log statements to litter the code but not debugger statements? There are fewer of them?

Re: Use console.log() like a pro (2020)

#155

> Using console.log() for JavaScript debugging is the most common practice among developers. But, there is more… Cut your debugging time, knowledge of console.log, and mental churn in half and set up your tooling to use a `debugger` statement. The console.log method may be used heavily but it’s actually a bad practice and often leaves code littered with log statements. Even for the purpose of logging itself you shoul…

I find use cases for both. Sometimes I want to run code and review the generated debug log, other times I want to step through interactively.

I find interactive debugging takes more concentration than a workflow of: form hypothesis, add the console.logs to prove/disprove it, run the code, and analyze the result.

Re: Use console.log() like a pro (2020)

#156
post #148
post #62

Earlier quoted context omitted.

Go to the desktop version and open the dev tools console :)

No output in Safari for some reason. I see it in Chrome.

oh really? Interesting, why wouldn't Safari support the console APIs? Huh, well, I'm going to take the high road and say Safari intentionally not supported for such-and-such high-minded reasons.
Post reply on HN