this post was submitted on 30 Sep 2023
317 points (91.6% liked)

Programmer Humor

32472 readers
849 users here now

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

Rules:

founded 5 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] Aabbcc@lemm.ee 69 points 1 year ago (3 children)

Because I have nested loops and only want to see certain cases and I'm not smart enough to set up conditional breakpoints or value watching

[–] HairHeel@programming.dev 27 points 1 year ago

Value watching is just printf; change my mind

[–] idunnololz@lemmy.world 8 points 1 year ago

Someone should make that bell curve meme with people using print statements at the newb and advanced level. Debuggers are great but I'd say it's a 50/50 split for me for debugger vs logger when I'm debugging something.

[–] DmMacniel@feddit.de 7 points 1 year ago (1 children)

Programming is also about learning your tools :)

[–] Aabbcc@lemm.ee 3 points 1 year ago

Looks like godot doesn't have it yet

[–] qprimed@lemmy.ml 58 points 1 year ago (3 children)

because, sometimes, having your program vomit all over your console is the best way to remain focused on the problem.

[–] charliespider@lemmy.world 11 points 1 year ago (1 children)

This is the reason for me. Sometimes I don't want to step through the code and just want to scan through a giant list of output.

load more comments (1 replies)
[–] ripcord@kbin.social 7 points 1 year ago

Similarly, every once in a while I'll throw warning messages (which I can't ship) to encourage me to go back and finish that TODO instead of letting it linger.

[–] MajorHavoc@lemmy.world 3 points 1 year ago

Exactly. And there's plenty of places where setting up a live debug stream is a massive PITA, and finding the log files is only a huge PITA.

[–] malockin@lemmy.world 48 points 1 year ago

because sometimes you need to investiagte an issue that happens only on the production machines, and you can't/shouldn't setup debugging on those.

[–] corytheboyd@kbin.social 41 points 1 year ago

Debugger good for microscopic surgery, log stream good for real time macro view. Both perspectives needed.

[–] GravelPieceOfSword@lemmy.ca 41 points 1 year ago (2 children)

As someone who has done a lot of debugging in the past, and has also written many log analysis tools in the past, it's not an ether/or, they complement each other.

I've seen a lot of times logs are dismissed in these threads recently, and while I love the debugger (I'd boast that I know very few people who can play with gdb like I can), logs are an art, and just as essential.

The beginner printf thing is an inefficient learning stage that people will get past in their early careers after learning the debugger, but then they'll need to eventually relearn the art of proper logging too, and understand how to use both tools (logging and debugging).

There's a stage when you love prints.

Then you discover debuggers, you realize they are much more powerful. (For those of you who haven't used gdb enough, you can script it to iterate stl (or any other) containers, and test your fixes without writing any code yet.

And then, as your (and everyone else's) code has been in production a while, and some random client reports a bug that just happened for a few hard to trace events, guess what?

Logs are your best friend. You use them to get the scope of the problem, and region of problem (if you have indexing tools like splunk - much easier, though grep/awk/sort/uniq also work). You also get the input parameters, output results, and often notice the root cause without needing to spin up a debugger. Saves a lot of time for everyone.

If you can't, you replicate, often takes a bit of time, but at least your logs give you better chances at using the right parameters. Then you spin up the debugger (the heavy guns) when all else fails.

It takes more time, and you often have a lot of issues that are working at designed in production systems, and a lot of upstream/downstream issues that logs will help you with much faster.

[–] fibojoly@sh.itjust.works 7 points 1 year ago

I've spent inordinate amounts of my career going through logs from software in prod. I'm amazed anyone would dismiss their usefulness!

[–] xmunk@sh.itjust.works 3 points 1 year ago* (last edited 1 year ago) (2 children)

Ahem, I'm a senior developer and I love prints. I appreciate debuggers and use them when in a constrained situation but if the source code is easily mutable (and I work primarily in an interpreted language) then I can get denser, higher quality information with print in a format that I can more comfortably consume than a debugger (either something hard-core like gdb or some fancy IDE debugger plugin).

That said, I agree about logging the shit out of everything. It's why I'm quaking in my boots about Cisco acquiring Splunk.

load more comments (2 replies)
[–] Scrath@feddit.de 38 points 1 year ago (2 children)

Try debugging a distributed embedded real time system which crashes when you are in a breakpoint too long because the heartbeat doesn't respond

[–] Croquette@sh.itjust.works 6 points 1 year ago (2 children)

Working with Nordic Semi Bluetooth Stack was like that when working with it a few years ago. If you reach a breakpoint while the Bluetooth stack was running, it would crash the program.

So printf to dump data while it ran and only break when absolutely necessary.

load more comments (2 replies)
[–] stardreamer@lemmy.blahaj.zone 5 points 1 year ago

Or just any dpdk program, where any gdb caused slowdown causes the code to "behave as expected"

[–] deegeese@sopuli.xyz 36 points 1 year ago

Because it takes 3 hours to reach the error and I’ve got other shit to fix.

[–] Knusper@feddit.de 29 points 1 year ago (2 children)

I found debuggers practically unusable with asynchronous code. If you've got a timeout in there, it will break, when you arrive at a breakpoint.

Theoretically, this could be solved by 'pausing' the clock that does the timeouts, but that's not trivial.
At least, I haven't seen it solved anywhere yet.

I mean, I'm still hoping, I'm wrong about the above, but at this point, I find it kind of ridiculous that debuggers are so popular to begin with.
Because it implies that synchronous code or asynchronous code without timeouts are still quite popular.

load more comments (2 replies)
[–] Steeve@lemmy.ca 23 points 1 year ago

Debugger? I hardly know er

[–] serratur@lemmy.wtf 22 points 1 year ago (2 children)

I still use print as a quick "debug" its just convenient to have multiple prints in the code when you're iterating and changing code.

load more comments (2 replies)
[–] Phoenix3875@lemmy.world 20 points 1 year ago

I have to print f to show respect.

[–] MonkderZweite@feddit.ch 19 points 1 year ago

Quick printf vs. setting up conditions.

[–] space@lemmy.dbzer0.com 15 points 1 year ago (1 children)

You can't run a debugger on a customer's machine.

load more comments (1 replies)
[–] eestileib@sh.itjust.works 13 points 1 year ago

Embedded Oldster : "Of course, we had it rough. I had to use a single blinking red LED."

Unix Oldster : "An LED? We used to DREAM about having an LED, I still have hearing loss from sitting in front of daisy wheel printers."

Punch-card Oldster : "Luxury."

[–] MooseBoys@lemmy.world 11 points 1 year ago (1 children)

Debuggers are for when you hit a problem with your code. Logs are for when someone else hits a problem with your code.

load more comments (1 replies)
[–] tdawg@lemmy.world 11 points 1 year ago

not all problems are worth busting out the heavy machinery (until they are)

[–] raubarno@lemmy.ml 11 points 1 year ago (1 children)

Uhh, I'm too lazy to learn all the GDB commands.

load more comments (1 replies)
[–] harrowhawk@lemmy.sdf.org 10 points 1 year ago

Because, sadly, I more often than not do NOT have access to a debugger.

Learning how to write good debugging print messages is a skill. And nicely transfers to writing good debug log messages. Which makes diagnosing user issues much easier.

[–] CarlosCheddar@lemmy.world 9 points 1 year ago (2 children)

If you’re debugging a react re-render for example where the error happens on the 7th re-render then having it pause with the debugger 7 times can be annoying.

I don't know about react, but in similar situations in java I use conditional breakpoints. Sometimes going as far as introducing a temporary variable to do the count for me, and basing my condition on that.

[–] DmMacniel@feddit.de 3 points 1 year ago (1 children)

You can do conditional breakpoints in a browser :)

load more comments (1 replies)
[–] Bishma@discuss.tchncs.de 8 points 1 year ago (1 children)

I honestly need to remember the debugger exists. They weren't common for interpreted languages when I got started.

[–] charliespider@lemmy.world 3 points 1 year ago

Grey beards merge and increment (ie: senior devs unite and rise up)

[–] MJBrune@beehaw.org 8 points 1 year ago (2 children)

The issue is a debugger will trigger every time. In video games at least you have code that runs as over and over again in tick. Putting debugger breakpoints in that would be useless most of the time. Print is where it's at for ticking/timer debugging.

load more comments (2 replies)
[–] guleblanc@lemmy.world 7 points 1 year ago

I used to work on a debugger. It was called TotalView, and it was a really stellar multiprocess, multithread debugger. You could debug programs with thousands of cores and threads. You could type real C++ code to inspect values, inject code into a running process, force the CPU to run at a given line, like a magic goto. But we had a saying "printf wins again". Sometimes you just can't get the debugger to tell you what you need.

[–] counselwolf@lemmy.world 6 points 1 year ago (2 children)

Coming off as a noob here, but how do you actually utilize the debugger.

Mostly working on python stuff in VS Code, sometimes I just run the code and look at the error. Sometimes I try the debug and run option but it acts the same as just running the code; there's some stuff like variables window but I don't know how to utilize the information to debug.

[–] isVeryLoud@lemmy.ca 7 points 1 year ago (1 children)

Debuggers allow you to step through code and inspect the program state at any moment during execution. You can even sometimes run commands inline to see how stuff reacts.

This means you can usually just hover a variable or something in your IDE while execution is paused and see its current value without having to restart execution every time you want to print something different.

[–] Enkers@sh.itjust.works 3 points 1 year ago* (last edited 1 year ago)

You can even sometimes run commands inline to see how stuff reacts.

It's honestly not a bad way to write some of the more complex lines of code too. In python/vscode(ium), you can set a breakpoint where you're writing your code and then write the next line in the watches section. That way you can essentially see a live version of the result you're getting. I especially like this for stuff like list comprehension.

[–] jjjalljs@ttrpg.network 4 points 1 year ago

I don't know how to use vscode. In general in Python you can do breakpoint() and your code will pause there and become interactive. If you're running in docker you'll want to attach to the container. When it hits the breakpoint you basically drop into a normal python repl with extra features.

https://docs.python.org/3/library/pdb.html

This is really, really, good for debugging and developing. You can interactively examine stuff and try stuff right there. You don't have to rerun the whole thing to be like "ok what's the second item in the list? Is this syntax right to sort it?" or whatever you're trying to do

I use pdb++ for syntax highlighting and some other qol features, too.

[–] MalReynolds@slrpnk.net 5 points 1 year ago

You're gonna want logging in production...

[–] nakal@kbin.social 5 points 1 year ago (2 children)

Because if you invested a lot of time on carefully choosing the places where printf should be to get all the info you need, you just need to unset NDEBUG and voilà everything that you need is there again.

load more comments (2 replies)
[–] hubobes@sh.itjust.works 4 points 1 year ago

Because for all the love I have for NGRX, debugging it is kinda hard.

[–] dingleberry@discuss.tchncs.de 4 points 1 year ago

The debugger can't handle the chonkers app I work on.

[–] killeronthecorner@lemmy.world 3 points 1 year ago

Because it's significantly slower to analyze a series of computations and their values when stepping through them

[–] HairHeel@programming.dev 3 points 1 year ago (1 children)

Later on when I want to look productive I’ll delete all those printfs then pay myself on the back for committing a lot of code changes that sprint and for reducing our log storage costs by 75%

[–] Bonehead@kbin.social 3 points 1 year ago

Don't delete printf statements...wrap them in a "if (DEBUG)" function. You still reduce the log storage costs while simultaneously expanding the code base and giving yourself a way to debug the system later.

[–] xilliah@beehaw.org 3 points 1 year ago

I rarely use the debugger. When I do it's because I'm tired and I always regret it tbh. It's just a waste of time and clutters my screen.

The fastest way by far is to simply read and think. You have to do it any way.

The print is the last resort, I tend to use it maybe once per day. Doesn't clutter my screen and works with the shortcuts I'm used to. Totally flexible. Can comment out and share with team or reuse later. The issue is often immediately clear.

For example today I used it on a position after a multiplication with a matrix. I didn't explicitly convert it from a float3 to a float4, so w was 0, and it caused it to rotate instead of translate the position vector. Once I printed it it became clear.

Had I just read the code again and thought about what it was actually doing I would've found it more efficiently.

load more comments
view more: next ›