214
all 23 comments
sorted by: hot top controversial new old
[-] mcv@lemmy.zip 40 points 1 week ago

Nothing wrong with console.log.

[-] TootSweet@lemmy.world 1 points 1 week ago

This is the way.

[-] bleistift2@sopuli.xyz 31 points 1 week ago

Sometimes there’s literally no other way (that I know of). When you’re debugging concurrency issues, stopping all time with a debugger just isn’t an option.

[-] marlowe221@lemmy.world 11 points 1 week ago

Yep, I’ve had times where the debugger was hiding the race condition that was the actual cause of my problem.

[-] Ephera@lemmy.ml 4 points 1 week ago

I guess, there's technically nothing which dictates that a debugger has to work by stepping through a program. It could also present you some diagram of variable values changing over time. But yeah, gonna be hard to find a more useful representation than those values being interleaved with your logs, at least for most applications. I have heard of more advanced debuggers being used in gamedev, which makes sense, since logs aren't nearly as useful there.

But yeah, given that most people think of the stepping debuggers, them being the default advice does feel emblematic of our industry still shying away from concurrency.

[-] mcv@lemmy.zip 2 points 1 week ago

I can also see the variables change by logging them.

Debuggers are great if you want to see in detail what's going on in a specific loop or something, but across a big application with a framework that handles lots of things in unreadable code, multiple components modifying your state, async code, etc.; debuggers are a terrible way to track what's going on.

And often when I've found where it goes wrong, I want to check what was happening in a previous bit of code, a previous iteration or call. Debuggers don't go back; you have to restart and run through the whole thing, again finding exactly where it went wrong, but now just a bit before that, which is often impossible.

With logging, you just log everything, print a big warning where the thing has gone wrong, and scroll back a bit.

Debuggers are a fantastic bit of technology, but in practice, simple logging has helped me far more often. That said, there are issues where debuggers do beat logging, but they're a small minority in my experience. Still useful to know both tools.

[-] barubary@infosec.exchange 2 points 1 week ago

Debuggers don’t go back; you have to restart and run through the whole thing

Yes, they do: https://rr-project.org/

https://sourceware.org/gdb/current/onlinedocs/gdb.html/Reverse-Execution.html

[-] mcv@lemmy.zip 2 points 1 week ago

This does sound very interesting. I should have said the debuggers I'm familiar with don't do it. Or if they do, I have no idea how.

Certainly setting breakpoints on certain conditions instead of just a line, would help a lot. Being able to step backwards through the execution even more so.

[-] Ephera@lemmy.ml 1 points 1 week ago

I mean, you should do general logging either way, since you won't have a debugger attached when running in production. And then you can typically scroll back in the logs, too, when the debugger has paused execution.

What this meme is talking about, is adding ad-hoc logs to narrow down where an error occurs while developing. So, bullshit logs like console.log("1"), followed by a line of potentially bad code and then console.log("2”). Log lines which you'll remove again when you're done debugging...

[-] dumnezero@piefed.social 1 points 1 week ago

console.log("functionOne", "A", varA, "B", varB, "C", varC);

[-] squeamish_ossifrage@lemmy.today 1 points 1 week ago

console.log('func', {A, B, C})

[-] dumnezero@piefed.social 1 points 1 week ago

While that works, of course, I avoid doing object construction or other logic beside some string concatenation in JS logs. And those string literals serve a purpose as semantic markers, not just as separators.

[-] vext01@lemmy.sdf.org 1 points 1 week ago

I wonder if rr would work for this scenario?

[-] moseschrute@lemmy.world 16 points 1 week ago
[-] AdamEatsAss@lemmy.world 25 points 1 week ago

console.log("here") console.log("here 2") console.log("here 3")

[-] Rambomst@lemmy.world 14 points 1 week ago

Please stop leaking my code.

[-] funkless_eck@sh.itjust.works 4 points 1 week ago

I sometimes write the (temporary) line number to get back to a suspect section quicker

[-] Serinus@lemmy.world 2 points 1 week ago

Oh my console.log messages are so much better than that now... (that I started telling copilot to add them for me).

[-] Bishma@discuss.tchncs.de 14 points 1 week ago

Yeah. Obviously that's what console.debug() is for.

[-] Pxtl@lemmy.ca 8 points 1 week ago

If you're making a programming platform and the only debugging tool you provide to developers is console logging, you're a monster.

yaml pipelines/actions I'm looking in your direction.

[-] HiddenLayer555@lemmy.ml 7 points 1 week ago

console.warn() to differentiate what you're looking for from the regular logs.

this post was submitted on 03 Oct 2025
214 points (100.0% liked)

Programmer Humor

38710 readers
45 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS