this post was submitted on 30 Sep 2023
374 points (90.1% liked)

Programmer Humor

32042 readers
1375 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 78 points 11 months 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 31 points 11 months ago (1 children)

Value watching is just printf; change my mind

[–] leo85811nardo@lemmy.world 7 points 11 months ago

Ackchyually, value watching in debugger almost guarantee to get the value by address, but printf in some languages can pass by value, unnecessarily make copy of the watched variable, and the value printed is the copied data instead of the original

[–] DmMacniel@feddit.de 10 points 11 months ago (1 children)

Programming is also about learning your tools :)

[–] Aabbcc@lemm.ee 4 points 11 months ago

Looks like godot doesn't have it yet

[–] idunnololz@lemmy.world 7 points 11 months 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.

[–] qprimed@lemmy.ml 63 points 11 months 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 16 points 11 months 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 9 points 11 months 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 5 points 11 months ago* (last edited 11 months 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.

Edit: But I've been promised AI will do both soon, so I'll stop stressing over it. /s

[–] malockin@lemmy.world 53 points 11 months 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.

[–] Scrath@feddit.de 50 points 11 months 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 8 points 11 months 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 6 points 11 months ago

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

[–] deegeese@sopuli.xyz 45 points 11 months ago

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

[–] corytheboyd@kbin.social 45 points 11 months ago

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

[–] GravelPieceOfSword@lemmy.ca 44 points 11 months 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 11 months 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 5 points 11 months ago* (last edited 11 months 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)
[–] Knusper@feddit.de 39 points 11 months 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 34 points 11 months ago

Debugger? I hardly know er

[–] Phoenix3875@lemmy.world 28 points 11 months ago

I have to print f to show respect.

[–] serratur@lemmy.wtf 27 points 11 months 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)
[–] irotsoma@lemmy.world 20 points 11 months ago

Depends on the language and platform as well as how asynchronous things are. For example, lots of platforms have little to no debugging for scripting languages. I write a lot of Groovy on a platform that has a debugger that is mostly too much trouble to connect my IDE to since the platform can't run locally. But even then it doesn't debug the Groovy code at all.

And with asynchronous stuff it's often difficult to tell what something isn't running in the right order without some kind of debug logging. Though in most cases I use the logger rather than printing directly to the console so that it can be left in and just configured to only print if the logging level is set to debug which can be configured based on the environment.

[–] MonkderZweite@feddit.ch 19 points 11 months ago

Quick printf vs. setting up conditions.

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

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

load more comments (1 replies)
[–] eestileib@sh.itjust.works 14 points 11 months 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 13 points 11 months 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.

[–] xmunk@sh.itjust.works 4 points 11 months ago

Nah, debug("Reached line 12"); is always acceptable. Using a formal debugger is a matter of personal preference - but everyone needs to be familiar with it at at least a surface level for whenever a coredump comes in.

[–] tdawg@lemmy.world 13 points 11 months ago (1 children)

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

load more comments (1 replies)
[–] dylanTheDeveloper@lemmy.world 13 points 11 months ago* (last edited 11 months ago)

I use Unreal quite alot and while I do print stuff to the log, for rapid prototyping I print string because it saves me precious seconds. Finished products will have logging for alpha testing since there's alot of log spam

[–] harrowhawk@lemmy.sdf.org 11 points 11 months 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.

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

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

[–] xmunk@sh.itjust.works 5 points 11 months ago* (last edited 11 months ago) (1 children)

The three you need for 99% of anything are break, print and s for step - with those the world is your debuggable oyster.

load more comments (1 replies)
[–] MalReynolds@slrpnk.net 10 points 11 months ago

You're gonna want logging in production...

[–] CarlosCheddar@lemmy.world 9 points 11 months 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.

[–] DmMacniel@feddit.de 4 points 11 months ago (1 children)

You can do conditional breakpoints in a browser :)

load more comments (1 replies)
[–] thetreesaysbark@sh.itjust.works 3 points 11 months ago

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.

[–] MJBrune@beehaw.org 8 points 11 months 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)
[–] Bishma@discuss.tchncs.de 8 points 11 months ago (1 children)

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

load more comments (1 replies)
[–] counselwolf@lemmy.world 6 points 11 months ago (3 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 9 points 11 months 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.

load more comments (1 replies)
[–] jjjalljs@ttrpg.network 5 points 11 months 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.

load more comments (1 replies)
[–] nakal@kbin.social 6 points 11 months 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)
[–] guleblanc@lemmy.world 6 points 11 months 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.

[–] hubobes@sh.itjust.works 4 points 11 months ago

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

[–] dingleberry@discuss.tchncs.de 4 points 11 months ago

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

[–] HairHeel@programming.dev 3 points 11 months 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%

load more comments (1 replies)
[–] xilliah@beehaw.org 3 points 11 months 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 ›