Live data from Hacker News

JavaScript debuggers are broken

samdesota.com

61–70 of 124 posts

Re: JavaScript debuggers are broken

#61

Brian W. Kernighan and Rob Pike wrote that stepping through a program less productive than thinking harder and adding output statements and self-checking code at critical places. Kernighan once wrote that the most effective debugging tool is still careful thought, coupled with judiciously placed print statements.

Just because two famous people didn't like step-debugging doesn't mean that there shouldn't be proper debugging tools beyond printf() ;) We need to be careful not falling into the cargo-culting trap (same as "Goto considered harmful").

Sure, blindly accepting what famous people say is problematic.

But then again, Kernighan, Pike and Dijkstra became famous because of merit and not because of whatever made Kim Kardashian famous. So it seems reasonable to at least entertain the ideas people like them put forward, instead of dismissing the ideas outright, or dismissing the idea after only the most superficial thinking.

Dijkstra make an argument that proper control structures (if-then-else blocks, for-while loops) are better than simulating those with goto. Not that every last use of goto was bad. And if you look at what code looks like these days, seems he was right, or at least most people thought he was. People do not use goto anymore, except for a tiny set of special use cases where it makes sense. E.g. jumping into the "cleanup" end of a function in C, because there is no better way in C to do it, really (no RAII, no python-style with/C# style using, no go-style defer). But you'll hard pressed to find good code, or any code really, that uses goto to implement looping when there are language level loop structures available.

The idea here is not that "all and every use of side-stepping debuggers is considered harmful", and not even "just sprinkle some printf()", but to use a combination of good self-checking design (aka defensive programming) that allows to sprinkle printfs()/tracepoints/breakpoints at interesting places instead of blindly stepping through huge blobs of code in a debugger.

I like to do that myself, add some error checks and some "output" and it usually works great and is very productive, and having the additional error checks is useful not just then but also in the future... But when it does not work out (legacy code, code other people wrote and I am unfamiliar with) then a step debugger might be a viable alternative especially if the other remaining alternative is "nothing/ask magic eight ball".

Re: JavaScript debuggers are broken

#62

Brian W. Kernighan and Rob Pike wrote that stepping through a program less productive than thinking harder and adding output statements and self-checking code at critical places. Kernighan once wrote that the most effective debugging tool is still careful thought, coupled with judiciously placed print statements.

I agree, if I get to write my own code from scratch.

Working in a pre-existing codebase with millions upon millions of lines of code written by others over years, having absolutely no idea in what context the function I'm looking at is even called, I need be able to to set breakpoints.

Re: JavaScript debuggers are broken

#63

I think JavaScript debuggers in browsers are AMAZING, it is fantastic to have such powerful programming tools on almost every computer! Just like BASIC in DOS computers and similar computers from that era, this is a programming language available by default almost everywhere. And the debugger tools are powerful too with inspecting and changing variables, ... But what did the author expect, when using a programming la…

Par for the course for any language and development environment is interactive debugger in the code you are writing. As the author I don’t care much about how many translation steps there are from “my” syntax to machine code, all I care about is that I can debug my own code and watch my own variables.

The grandparents point is (I guess) that if choosing a reasonable language (such as TS) instead forces you to give up another must-have (e.g interactive debugging) then something is wrong with the tooling. I read others that claim they have working ts debugging so it’s certainly possible, but I’ll add one more par-for-the-course bullet point: it should work out of the box.

Re: JavaScript debuggers are broken

#64

It's not the debugger that is broken, it's the entire JS ecosystem. It's such a terrible language we spent the last 2 decades fixing its warts, adding one layer on top of the other. And now you have es7 + typescript + jsx + some magic introspection + code splitting + weird non standard imports, all that turned into regular JS and source maps, in a complex concurrent and async env that deals with graphics AND the netw…

The problems you describe are in most languages. Networking and graphics are quite easy in JavaScript. Nothing fancy or complex about that. Debuggers are super light weight. Build into most browsers. Async programming is just another way. Again nothing fancy and complex about it. You just need to understand it.

E = MC2 is just a regular equation. Nothing complex about it. You just need to understand it.

Re: JavaScript debuggers are broken

#65

Brian W. Kernighan and Rob Pike wrote that stepping through a program less productive than thinking harder and adding output statements and self-checking code at critical places. Kernighan once wrote that the most effective debugging tool is still careful thought, coupled with judiciously placed print statements.

Not a big REPL user I guess.

Re: JavaScript debuggers are broken

#66
post #39

Brian W. Kernighan and Rob Pike wrote that stepping through a program less productive than thinking harder and adding output statements and self-checking code at critical places. Kernighan once wrote that the most effective debugging tool is still careful thought, coupled with judiciously placed print statements.

It is much more efficient to place a breakpoint at the spot where you would have put the print statement and then inspect the values of interest in the debugger. It is a rather false dichotomy to assume that using better tools precludes you from "careful thought".

A debugger is very useful when you trace a piece of code that 1) you understand well and 2) executes relatively linearly. JavaScript is pretty terrible at both.

First of all, most JavaScript apps are just a small chunk of code that sit on frontend frameworks (React etc). This means that using a debugger, you mostly step through framework's internal code base, of which you have a vague understanding at best.

Also, an average JavaScript code hops around -- to put it mildly -- crazily, due to the heavy usage of anonymous functions, callbacks and other very cleaver abstractions.

This is why placing a bunch of console.log beats tracing with a debugger.

Re: JavaScript debuggers are broken

#67

I think JavaScript debuggers in browsers are AMAZING, it is fantastic to have such powerful programming tools on almost every computer! Just like BASIC in DOS computers and similar computers from that era, this is a programming language available by default almost everywhere. And the debugger tools are powerful too with inspecting and changing variables, ... But what did the author expect, when using a programming la…

Par for the course for any language and development environment is interactive debugger in the code you are writing. As the author I don’t care much about how many translation steps there are from “my” syntax to machine code, all I care about is that I can debug my own code and watch my own variables. The grandparents point is (I guess) that if choosing a reasonable language (such as TS) instead forces you to give up…

Well so it's the title of the article that ticks me off, "JavaScript debuggers are broken"

Isn't instead the language the author is using (JSX?) that's broken by not providing a debugger for itself or compiling to an easier to debug form?

Re: JavaScript debuggers are broken

#68

Brian W. Kernighan and Rob Pike wrote that stepping through a program less productive than thinking harder and adding output statements and self-checking code at critical places. Kernighan once wrote that the most effective debugging tool is still careful thought, coupled with judiciously placed print statements.

Then why create new languages at all? Just 'think harder' about the assembly language someone else wrote.

Re: JavaScript debuggers are broken

#69

Brian W. Kernighan and Rob Pike wrote that stepping through a program less productive than thinking harder and adding output statements and self-checking code at critical places. Kernighan once wrote that the most effective debugging tool is still careful thought, coupled with judiciously placed print statements.

Clearly the guy didn't have to pull out a working PoC in one week with a forced uppon JS framework that just changed its public API and not its doc and that need magic lines just for webpack to not crash. Or that has to pull data from a manually written csv our client uploads at 3 pm on their managed ftp and an untested REST api designed last month by a one man start up, using a legacy client lib that only god and a…

This says much more about the work environment front-end developers are subjected to than anything else.

Re: JavaScript debuggers are broken

#70

Earlier quoted context omitted.

Just because two famous people didn't like step-debugging doesn't mean that there shouldn't be proper debugging tools beyond printf() ;) We need to be careful not falling into the cargo-culting trap (same as "Goto considered harmful").

Sure, blindly accepting what famous people say is problematic. But then again, Kernighan, Pike and Dijkstra became famous because of merit and not because of whatever made Kim Kardashian famous. So it seems reasonable to at least entertain the ideas people like them put forward, instead of dismissing the ideas outright, or dismissing the idea after only the most superficial thinking. Dijkstra make an argument that pr…

Sorry for moving the discussion a little bit off-topic, but I like the "Goto considered harmful" as example of cargo-culting, because Dijkstra wrote this when structured-programming wasn't common, and a goto at that time literally meant "jump anywhere in the entire program", like GOTO works in BASIC.

Meanwhile, goto has been tamed and has become a part of the structured-programming-toolset. In C you cannot jump out of the current function with a goto, it's just a slightly more flexible break/continue/return. The meaning of goto has changed completely, yet people still use the "Goto considered harmful" meme as if nothing had changed since Dijkstra wrote that ;)

Post reply on HN