News for hackers. Stuff that matters.
Re:JavaScript debuggers are broken by perfunctory on Monday April 22, 2019 @05:48AM (#19717625)
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.
Re:JavaScript debuggers are broken by sametmax on Monday April 22, 2019 @07:25AM (#19718013)
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 fired engineer knew how to get to work.

Or that has to be done with a trainee designer that knows photoshop but will "learn this css thing on the way" , a remote turkish consulting firm and your boss dog barking next to you because animals are good for moral and we are agile right ?

Those theories are good in a lab while writting carefully crafted c for the board you designed the spec for.

Re:JavaScript debuggers are broken by Tade0 on Monday April 22, 2019 @08:13AM (#19718266)
This says much more about the work environment front-end developers are subjected to than anything else.
Re:JavaScript debuggers are broken by sametmax on Monday April 22, 2019 @08:18AM (#19718303)
Or work with a geographer client that wants to integrate his first terrible, terrible plugin into postgis.

Or contribute to a mess of an open source project that your microservice happen to depend on.

Or debug your student exercice that found yet a brand new way to crash that you never heard of.

Or find what are the side effects of your 3am emergency fix during the last red teaming.

Programming is a vast land.

Re:JavaScript debuggers are broken by retiredcoder on Monday April 22, 2019 @07:36AM (#19718075)
True, I am big fan of them but there are some legitimate cases where a debugger is so practical.

There is a lot of code out there that has very little logical sense per se other than elusive business requirements..

Re:JavaScript debuggers are broken by ubercow13 on Monday April 22, 2019 @06:13AM (#19717725)
Debuggers implement this but better. You can place a conditional breakpoint containing your code checks, and when execution stops you have access automatically to all the scope you could possibly use to print your output statements without having to write any. You are also free to still think carefully while using a debugger.
Re:JavaScript debuggers are broken by lugg on Monday April 22, 2019 @06:52AM (#19717867)
No. You're misrepresentating or misunderstanding the claim.

It is not about debugging. It is about program design. If you need to step through execution in order to understand and reason about iit then your design is too complex.

It is not a claim that print and conditionals are better debugging techniques. It is a claim that having those critical points in execution making assertions and logging warnings is a more productive alternative which precludes debugging in the first place.

> have access automatically to all the scope you could possibly use to print your output statements without having to write any.

If youre in a context where you need this level of access to the state scope you have a ball of mud that needs to be decomposed. You should know what state you have by the failure mode or the failing test at hand.

Using a debugger only makes sense if you're dealing with a mess. Fix the mess don't build tools to work with it.

> You are also free to still think carefully while using a debugger.

Yes but again, if you need a debugger it goes to show you don't think carefully very often so maybe telling me you can with a debugger is kind of aoot point when I know you won't.

Re:JavaScript debuggers are broken by flohofwoe on Monday April 22, 2019 @07:10AM (#19717941)
I'm sorry but this reasoning sounds like elitist rubbish to me, like trying to turn a completely subjective workflow step into a universal law ;)

It's not about a "need to step through because your code is too complex", more about validating the code you just wrote, whether it still "feels right" after it has been dumped from your mental model into actual code.

You may have carefully thought about your program for hours before typing the first line of code, but usually such a splendid plan doesn't survive the first written line. Maybe the super-intuitive API you thought about doesn't quite feel that great in practice, maybe in the end you still didn't think "hard enough" about some problem. Spending time in the debugger to think about solutions is usually better than "just thinking hard" about solving the problem, because you have more data, and can tinker with potential solutions, and finally figure out which of the potential solutions feels best.

It's the same reason you're using a profiler for performance optimization, not just thinking about how to make the code faster (of course that needs to happen too, but it's not enough).

This sort of "validation debugging" in a tight edit-debug loop requires that the debugger runs in the same environment as the source code editor. It must be possible to switch between editing and debugging (and running to the location you edited) in under a second.

Re:JavaScript debuggers are broken by lugg on Monday April 22, 2019 @11:50AM (#19719851)
You've repeated AP's failing this isn't a workflow nor a replacement replacement debugging concept. It is a design paradigm that lessens the need for heavy weight debugging.

Debugging still has its usecases. I, like others, just see it as an infrequently required tool when most systems when properly composed simply lack the complexity required to make them useful.

> It's not about a "need to step through because your code is too complex", more about validating the code you just wrote, whether it still "feels right" after it has been dumped from your mental model into actual code.

Debuggers are for debugging. Not development.

It's not a rule without excception but in the general sense I would be very concerned to see a developer using the debugger on a daily basis especially if they're using it for state validation.

Like what are you validating that your tests aren't? Why aren't your tests validating it?

The need for a debugger is a symptom of a sick system. I have never required a debugger on a healthy system.

I've used them on healthy systems for more complex problem sets but by and large I only reach for them when someone has done something appalling.

Re:JavaScript debuggers are broken by almostdeadguy on Monday April 22, 2019 @05:15PM (#19723074)
> Like what are you validating that your tests aren't? Why aren't your tests validating it?

Your tests are probing your code on a narrow range of inputs (or if you're using something like property testing, potentially a larger but still finite range) drawn from the valid state space that is almost always too large to actually verify. They're also themselves pieces of code that itself can have bugs. Formal methods can prove properties about code, but usually w/ a much larger investment of time.

> The need for a debugger is a symptom of a sick system. I have never required a debugger on a healthy system.

I think people who say stuff like this are probably a little in denial about how many bugs they've actually written and how difficult it is to get any kind of certainty about the correctness of their code. Programmers write bugs, why are we policing the tools they use to fix them?

Re:JavaScript debuggers are broken by lugg on Tuesday April 23, 2019 @10:47AM (#19729146)
> Your tests are probing your code on a narrow range of inputs drawn from the valid state space that is almost always too large to actually verify.

You don't need to verify all inputs with mathematical certainty. You're writing the code some reasonable shortcuts can be made, some basic understanding of what bugs happen and what kinds of tests provide the best ROI gets you > 80% of the way there.

> They're also themselves pieces of code that itself can have bugs.

No, they are tests, bugs in test code are incredibly hard to produce if you are practicing test first development.

Most real bugs that make it into production are from conditional flows that are not being covered by tests.

> I think people who say stuff like this are probably a little in denial about how many bugs they've actually written

No denial, I know I've written a bug before.

> and how difficult it is to get any kind of certainty about the correctness of their code

Nope, not in denial about this either, I find it relatively easy. Maybe I just don't do a lot of rocket science or something.

> Programmers write bugs, why are we policing the tools they use to fix them?

Nobody is policing tool usage here..

Re:JavaScript debuggers are broken by mikeschinkel on Saturday April 27, 2019 @01:46AM (#19764008)
> Nobody is policing tool usage here..

> I would be very concerned to see a developer using the debugger on a daily basis especially if they're using it for state validation.

Those two statements seem to be in conflict.

Or maybe I should say that latter is not "policing" so much as "patronizing" in a condescending manner.

Re:JavaScript debuggers are broken by _slyo on Monday April 22, 2019 @10:44PM (#19725164)
> Like what are you validating that your tests aren't? Why aren't your tests validating it?

I use use a debugger fairly regularly when I'm writing tests. Debuggers are for moments of incredulity. When a test doesn't behave as I expect, I go back and look at my code. I'll look back and forth, and if I still don't see the root cause, then I'll fire go up gdb instead of adding print statements. Debugging a unit test is often way faster than recompiling.

Re:JavaScript debuggers are broken by mikeschinkel on Saturday April 27, 2019 @01:38AM (#19763987)
> Using a debugger only makes sense if you're dealing with a mess. Fix the mess don't build tools to work with it.

I have long thought if I was unable to use a good IDE debugger I would just change careers. Why? Because often I make the wrong assumption about the data that library or 3rd party functions will return. It is not until I can actually see the data that I realize my assumptions were wrong.

Using a debugger is all about learning, and debuggers make learning faster.

I am often able to code rings around my peers on projects. And I believe the reason is not because I am better or smarter but because I use a good IDE and debugger. And they don't.

Re:JavaScript debuggers are broken by flohofwoe on Monday April 22, 2019 @06:14AM (#19717727)
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").

Re:JavaScript debuggers are broken by rndgermandude on Monday April 22, 2019 @08:04AM (#19718205)
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 by flohofwoe on Monday April 22, 2019 @08:14AM (#19718271)
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 ;)

Re:JavaScript debuggers are broken by rndgermandude on Monday April 22, 2019 @12:00PM (#19719971)
Well, even today it's not entirely useless as a mantra: I have seen a lot of "hardware" and "signals" people in university who when they first had to do something in C or C++ used goto instead of loops and if blocks, coming from an assembler mindset probably where you have to (conditionally) jump (aka goto) around. I had people come to me and ask me "how do you do goto in java" in a java class where I was kinda a TA-A. "Goto considered harmful* (*most of the time, in higher level languages)" still served as a good enough rule of thumb.
Re:JavaScript debuggers are broken by goto11 on Monday April 22, 2019 @06:32PM (#19723699)
But the actual argument Dijkstra makes against goto applies to any use of goto (and would also apply to break and continue and to multiple returns).
Re:JavaScript debuggers are broken by patrec on Monday April 22, 2019 @08:22AM (#19718321)
What would they know? This was written twenty years ago, and as far as I'm aware neither of them had any relevant experience with languages that allow for debugger-driven development, production quality selective tracing or anything of any sophistication.

A lot of programming these days involves sending and interrogating complex data via awkward and ill-documented APIs and no amount of abstract a-priori thought or judicious print statements (and good luck printing anything with complex structure with C or Go) is gonna come anywhere close to being able to do an API call, drop into the debugger to see what's going wrong, pretty print deeply nested data sanely and effortlessly and fix up some code or value in the debugger and press on.

Re:JavaScript debuggers are broken by tonyarkles on Monday April 22, 2019 @11:15AM (#19719523)
Sounds like you could benefit from a REPL!

Edit:

> awkward and ill-documented APIs

As someone else mentioned, that sounds more like a work environment problem. If using a debugger allows crap like that to persist, maybe it's better for everyone if we tone down how much we use debuggers.

Re:JavaScript debuggers are broken by patrec on Monday April 22, 2019 @04:36PM (#19722714)
> As someone else mentioned, that sounds more like a work environment problem.

Have you ever used any API by, say, a major cloud provider? For example biquery and google docs are both a buggy mess despite being high profile, long established products. Using libraries like pandas is an exercise in figuring out by trial and error how to get it not to corrupt your data and which of the recommended ways of doing things don't involve a 2 orders of magnitude performance defect.

I'm in fact mostly using "repl"-driven development for these types of problems, but of course it's inferior to what I mean by debugger driven, a crippled subset to be precise. The scare quotes are because most languages don't have real read-eval-print-loops either, but something less powerful.

Unfortunately to the best of my knowledge there are basically only two languages which support this: Common Lisp and Smalltalk (maybe factor or something else really fringe also does) and I haven't used either in years. What I mean by debugger-driven is that you can literally write your whole program without ever restarting it, from the debugger. By contrast python can't even properly reload a changed module definition.

Interestingly it's hard to google good explanatory links, but the point is that you can write some code, run into a problem, and fix the problem right there, in the debugger without aborting the current execution or unwinding the stack.

Common Lisp and Smalltalk both have a bunch of unique features that make this type of thing very powerful, for example some function calls another function that's not defined. In python you'd be screwed at this point and restart your program from scratch. In Common lisp you can just write the missing function, compile it and continue the current execution frame as if nothing ever happened. This is because Common Lisp, unlike any remotely popular language allows for resumable exceptions where you can continue from just before the error happened (it also has the usual stack unwinding exceptions).

Here's two examples I found :

https://www.reddit.com/r/programming/comments/65ct5j/a_pytho... https://malisper.me/debugging-lisp-part-1-recompilation/

Concerning low-overhead, selective tracing (that you can run in production without fear of bringing the system down): erlang for example has nice support for this, see e.g. https://github.com/massemanet/redbug (although again unfortunately it will be difficult to grok without any prior erlang exposure).

Re:JavaScript debuggers are broken by tonyarkles on Monday April 22, 2019 @07:55PM (#19724297)
We are on the same page friend!

I’m glad to know that I’m not the only one who thinks a bunch of the cloud APIs are insane. I haven’t had to deal with any of that for about a year now, and I’m quite happy about that.

Re: Python and pandas, I haven’t used pandas, but did quite a bit of numpy/scipy/matplotlib stuff in the past. Jupyter doesn’t quite get where you’re talking about, but it does handle the “only have to repeat one step” things very well.

I only recently feel like I truly grokked the magic of the Common Lisp restart/repl/debugger stuff. Just the other day I used quicklisp to install a package, and at runtime it failed to open a C library (libsdl2-image.so or something like that). While it was paused asking what to do, I used apt to install the missing libraries and told it to retry. Boom. Program was running, and I hadn’t had to restart it even though a shared library was missing when I started it. Hacking on the little game I was fiddling with, I could C-c C-c as I added features to the game and keep playing it with the changes. Un-friggin-believable.

Edit: and yes, if I have to make a backend service these days, it’s generally in Elixir. Not quite the same as the beautiful Lisp stuff, but when your processes are expected to die all the time, it’s really easy to iterate quickly while keeping the system up. I feel like mistakes I make while writing Elixir code help make my overall system stronger.

Re:JavaScript debuggers are broken by patrec on Tuesday April 23, 2019 @01:53AM (#19725928)
Yup, your apt-get example is a great one. It's very frustrating that the ability to do stuff like this completely died with common lisp/smalltalk . I don't see the appeal of exceptions at all if you don't have restarts (I'd rather have Either).
Re:JavaScript debuggers are broken by ninkendo on Monday April 22, 2019 @08:05AM (#19718209)
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 by mistersys on Monday April 22, 2019 @02:12PM (#19721210)
Hi. I'm the author of the post.

I actually agree here. As soon as I realize it's going to be non-trivial for me to trace the issue with the debugger, more and more instead of setting up complex conditional breakpoints I just step back from the computer and have a think, and white board out my current understanding of how things are working. Usually, I get an "aha!" moment pretty quickly.

However, sometimes I don't get that "aha!" moment quickly, it random issues endup taking 30 minutes to hours to trace.

What I've come to understand is that's only true because debuggers are so limited. For example, white-boarding out the problem is incredibly useful.. why can't my debugger do that for me, by presenting a number of ways to layout the program and some filters so I can just view my code as graph and watch execution slowed down? Today's debuggers even in their best form are like looking through a tiny peep hole at a picture, I can only see this tiny section... but I want to see the whole picture.

Re:JavaScript debuggers are broken by intrasight on Monday April 22, 2019 @07:55AM (#19718157)
I agree. And isn't programming about automation and repeatability? A debugger session is manual and one-off. Early in my career I spend a lot more time in debuggers. Now I go months without using a debugger.
Re:JavaScript debuggers are broken by danmaz74 on Monday April 22, 2019 @01:38PM (#19720879)
I try not to get into situations where I need a debugger, but when that happens, having a debugger makes a huge difference compared to using print.
Re:JavaScript debuggers are broken by intrasight on Tuesday April 23, 2019 @03:10PM (#19731814)
Absolutely. But I think that years of programming has resulted in sort of an internal/mental debugger :)
Re:JavaScript debuggers are broken by breatheoften on Monday April 22, 2019 @01:34PM (#19720836)
Debugger's have uses beyond just debugging.

The article mentions a strategy of defining an empty function with a breakpoint when writing code for new functionality -- 'I'll write that code when I hit the breakpoint' can be an extremely fast path to productivity boost. Having the program state in front of you to inspect can really make it easier to write the code for a new piece of functionality.

Re:JavaScript debuggers are broken by agumonkey on Monday April 22, 2019 @05:50AM (#19717630)
it's odd that debuggers aren't helpful.. aiding in problem space reduction should yield improvements, but maybe depth first tracing is not the right tool here
Re:JavaScript debuggers are broken by mikeschinkel on Saturday April 27, 2019 @01:33AM (#19763972)
I would argue that both Brian W. Kernighan and Rob Pike are exceptionally bright individuals, and likely able to hold considerable more abstract complex thought in their heads than the average person.

One of the bigger blindspots I find with exceptionally bright people is they have no concept of how their brains are capable of things that far exceed the capabilities of the average person.

Or said another way, of course Brian W. Kernighan and Rob Pike think that thinking harder is better than experiencing and seeing. Because they can.

#jmtcw

Re:JavaScript debuggers are broken by clamiax on Monday April 22, 2019 @07:19AM (#19717980)
Totally agreed: proper thinking (not hard thinking but proper) on how to design programs makes most debuggers tools useless. Kernighan and Pike, but also Thompson, Ritchie, etc. perfectly understood this 20 years ago. I would not be surprised to learn that they never had the needs to use something like gdb in their nontrivial C programs.

I think JavaScript is a special case because it's too much complex by design.

Re:JavaScript debuggers are broken by goto11 on Monday April 22, 2019 @06:11AM (#19717709)
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".

Re:JavaScript debuggers are broken by teambayleaf on Monday April 22, 2019 @08:09AM (#19718238)
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 by curioussavage on Monday April 22, 2019 @01:42PM (#19720922)
What? It jumps around because it’s running in an event loop. Not because JS devs try to do too many clever things. You hope it jumps around often or you might be blocking the loop for too long.
Re:JavaScript debuggers are broken by matwood on Monday April 22, 2019 @07:38AM (#19718083)
Now that you brought it up this way, I realized that I rarely step through the code. Instead I use break points + inspect like I would a print statement.

I find this a much more efficient workflow.

Re:JavaScript debuggers are broken by vmware513 on Monday April 22, 2019 @06:26AM (#19717773)
I actually really like to debug Ember.js code. Because of the source map, I always see my code as I wrote it and I know when I'm in the framework's code.

Clean, well written and modern framework, like Ember.js, which supports the developer and help to implement features much faster are great choice and you won't have those problems what were mentioned in the article.

Use great tool not the hyped one...

https://emberjs.com

Re:JavaScript debuggers are broken by mercer on Monday April 22, 2019 @08:50AM (#19718477)
I have to admit I find it rather puzzling and a little amusing that randomly promoting Ember.js, of all things, is apparently your thing.

I mean, I sort of get the intercooler.js dude (if anything, I kind of came around to his perspective and am now all in on Phoenix' LiveView), and I can see how people would be all into Go and whatnot, but Ember is one of those things that I just don't understand anyone being evangelical about..

Re:JavaScript debuggers are broken by snarfy on Monday April 22, 2019 @08:11AM (#19718249)
Then why create new languages at all? Just 'think harder' about the assembly language someone else wrote.
Re:JavaScript debuggers are broken by caseymarquis on Monday April 22, 2019 @08:07AM (#19718222)
Not a big REPL user I guess.