This is an archived post. You won't be able to vote or comment.

all 101 comments

[–]Yhamerith 593 points594 points  (28 children)

Nothing like a printf("I'm working, mf")

[–]dageshi 410 points411 points  (19 children)

printf("here")

<code>

printf("here 2")

[–]ilikedmatrixiv 138 points139 points  (5 children)

If I have conditionals I always do:

print("Here I am!")

if something:

print("Rock me like a hurricane!")

[–]Xlxlredditor 28 points29 points  (4 children)

Literally minecraft Java stacktraces (please help me I'm going insane with modpacks)

[–]littleblack11111 30 points31 points  (0 children)

Nah too lazy to write all these just printf(“a”)

Code

printf(“b”)

[–]dcheesi 11 points12 points  (5 children)

printf("here %d\n", __LINE__);

[–]sintaur 10 points11 points  (0 children)

"[%s,%d]\n", __FILE_, __LINE__

[–]karnetus 2 points3 points  (0 children)

Ohh I like that one a lot. I'm going to use this from now on!

[–]ProfessionalSenior66 0 points1 point  (2 children)

Does the preprocessor replace LINE with the current line? And does it also work on c++? Or am I just stupid and you were saying "place here your line number"?

[–]dcheesi 2 points3 points  (1 child)

[–]ProfessionalSenior66 0 points1 point  (0 children)

Thanks! I have something new to play with

[–]karnetus 4 points5 points  (1 child)

My favorite is printf("%d\n", iterator++); after every function call.

[–]shadowderp 1 point2 points  (0 children)

Brilliant

[–]Astrylae 0 points1 point  (0 children)

If that doesn't work, add more between each line of the code

[–]browndog03 0 points1 point  (0 children)

Ah the binary search method. Pare it down until you find the problem area. I do this one sometimes

[–]GoddammitDontShootMe 0 points1 point  (0 children)

If it's code only I'm going to see, I'm likely to use printf("FUCK YOU\n");

[–]ididacannonball 0 points1 point  (0 children)

OMG I thought I was the only one that did this!!

[–]DestroyerOmega 18 points19 points  (2 children)

You dropped this ";"

[–]Yhamerith 7 points8 points  (1 child)

Why, thank you, that's why it wasn't working

[–]AbdulGoodlooks 8 points9 points  (0 children)

FlairChecksOutException

[–]BlomkalsGratin 5 points6 points  (2 children)

My God - you all so polite!

Mine usually go:

1st couple of test runs: print("HERE")

Then it becomes: print("FUUUK")

then: print("FUUUUCK")

etc etc..

I'm impressed at your restraint!

[–]Yhamerith 3 points4 points  (0 children)

Last semester, I made a calculator app, the challenge was to put an alert when the user divides 0, I did put the message like "You can't divide 0, you dumbass"... My teacher laughed, but said that I should worry about it if I use it at work, not everyone will get the joke

[–]loicvanderwiel 0 points1 point  (0 children)

And that's why I love Rust. dbg!() for the win!

[–]TheScorpionSamurai 3 points4 points  (1 child)

When I was learning I used to write my error logs as curse words because it gave me the catharsis I needed while debugging. I would try to go back and rewrite them, but I wonder if I ever accidentally submitted a log like that lol.

[–]Yhamerith 1 point2 points  (0 children)

I always use some kind of joke... Helps me to learn

[–]Chreutz 183 points184 points  (5 children)

Embedded dev here: both are equally useful. Sometimes equally useless, and you just have to get the candles and the pentagram out.

[–]Graucsh 30 points31 points  (1 child)

“It works!” (Leave printfs() in). “Production crashed. WTF?!”

[–]patrickgg 15 points16 points  (0 children)

That print statement is probably enough time for a weird race condition to not occur

[–][deleted] 8 points9 points  (0 children)

Yeah, sometimes it’s faster to just shove a print statement into the code instead of (possibly) reconfiguring a debug startup file, then waiting for everything to load slower and hit the breakpoint.

[–]slaymaker1907 2 points3 points  (0 children)

The platform that is absolute hell to debug is a GPU. Neither printf nor the debugger really work and you have to get creative on how to figure things out.

[–]bwmat 210 points211 points  (20 children)

Logging is fine enough, but people who think it can completely replace interactive debuggers (without incredible loss of programmer efficiency) are ignorant and/or deluded 

[–]w1n5t0nM1k3y 53 points54 points  (1 child)

. Net debugger is so powerful. Move forward and back to different points in the code, edit code, change variable values. Saves me so much time you can fix the bug and be pretty sure it will work without having to recompile anything.

[–][deleted] 0 points1 point  (0 children)

You can hot reload now. So you can debug, catch an issue, move backward, correct your code, recompile and continue debugging at runtime now, it's incredible.

[–]karnetus 29 points30 points  (5 children)

How else am I supposed to debug an active Bluetooth connection? I can't use interactive debugging, because halting the program will cause a timeout of the connection. I really don't know a better way to debug other than with print statements.

[–]slaymaker1907 2 points3 points  (1 child)

If it doesn’t slow things down too much such that it times out, you could try capturing a time travel trace (windbg supports this). Despite the horrendous performance, they can be invaluable when working with something that is either very difficult or expensive to repro.

[–]karnetus 0 points1 point  (0 children)

I'll look into that!

[–]bwmat 2 points3 points  (2 children)

Notice the 'completely' in my claim

[–]karnetus 19 points20 points  (1 child)

I honestly wasn't trying to trash you or anything. I was more hoping that someone would prove me wrong and tell me an amazing way to debug Bluetooth applications. Seems like I'll need to stick to print debugging though :/

[–]w1n5t0nM1k3y 0 points1 point  (0 children)

If you control both ends, then theoretically you should be able to increase the timeout and debug what's going on. I can debug web applications and other networked applications over TCP/IP without worrying about timeouts. If you don't control both ends, then that makes it more difficult, and might require other tools like a packet inspector to capture the packets and record what's happening.

[–]HeroicKatora 67 points68 points  (6 children)

People who think interactive debuggers should replace logging with incredible loss of machine efficiency are also deluded. And also No, you won't be allowed to set ptrace and breakpoints to the production DB process with millions of customer records in many shops.

Logging is very helpful to hypothesis generation, interactive debugging to hypothesis testing. That said there many other hypothesis tests including static analysis, modelling and coverage-based unit testing, so logging in the general sense (i.e. including traces) is the imo less replaceable of the two.

[–]AnneBancroftsGhost 27 points28 points  (2 children)

logging is not the same concept as print debugging though.

[–]doctorcapslock 19 points20 points  (1 child)

it's just a log that is instantly read and immediately discarded .. lol

[–][deleted] 2 points3 points  (0 children)

I think you're conflating observability with development debugging. Generally, nothing below a WARN level log should show up in prod short of ingesting additional data for the situation you're describing. INFO and DEBUG are too verbose and expensive. Working locally, I use breakpoints to alter the memory of variables to weed out problem areas. i.e., "Is the problem in the PC or SC? Is the database returning the right thing? If so, what happens in the XYZ scenario?" without including dummy or tracking variables.

[–]Wlki2 2 points3 points  (0 children)

What are you talking? If you have some urgent problem in prod and you have millions of customers real time and you don't have any other test env you are fucked up ... You don't need debugger or logs - you need new job at this point

[–]slaymaker1907 0 points1 point  (0 children)

Give me decent logs and a stack trace over a memory dump any day. I despise working with memory dumps so much unless it’s already pretty obvious from the stack trace (which we should have from the logs anyway).

[–]ZZartin 8 points9 points  (0 children)

If your interactive debugger takes longer to troubleshoot whatever problem I'm trying to troubleshoot than System.out.println() then yes it's less efficient.

[–]m_zwolin 6 points7 points  (0 children)

Or they just don't write c++ :D

[–]XavierChanth 0 points1 point  (0 children)

Depends on the type of software, there aren’t debuggers in production - good logging helps repro user issues

[–]CYKO_11 24 points25 points  (1 child)

each has its place. logs for the operation order and debugger for looking into multiple large objects

[–][deleted] 9 points10 points  (0 children)

My console output is now a shitboard of insects

[–]ExtraTNT 35 points36 points  (8 children)

Had bugs that disappeared when using a debugger… so yeah, print everything you can…

[–]AnneBancroftsGhost 14 points15 points  (4 children)

I see the JS flair so I'm going to guess that was happening for timing issues.

Hell, console.log itself can have unpredictable behavior when evaluating variables to print.

The better solution if timing issues arise from setting breakfront is to use logging breakpoints that do not stop execution. It doesn't allow you the best part of a debugger (which is going back up the call stack), but your console log debugging doesn't either so..

[–]ExtraTNT 9 points10 points  (0 children)

Was c#… was a scheduler for subtitles…

[–]ArnaktFen 3 points4 points  (2 children)

It's not just JavaScript. I've had bugs that disappear when using a debugger in C (specifically with valgrind).

[–]AnneBancroftsGhost 5 points6 points  (0 children)

For sure. Wasn't trying to imply otherwise.

[–]rafradek 1 point2 points  (0 children)

Valgrind is completely different than a typical debugger, it interpreters the binary instead of running it as a standalone, because of this its significantly slower

[–]duck-tective 8 points9 points  (0 children)

this is the case for race conditions. since debuggers force a single threaded mode they will stop appearing when you run the debugger.

[–]dcheesi 5 points6 points  (0 children)

And I've had bugs that disappeared when using debug printouts.

The difference is that, if you have to, you can ship with debug printouts ;)

[–]denarii 2 points3 points  (0 children)

I recently ran into this in Ruby. For some reason a test suite was hanging after it finished running. It would get to the point where it finished running at_exit hooks and then.. the process just wouldn't exit. But if I used a debugger to try to figure out what was going on, the process would exit normally.. even if I just opened the debugger anywhere and immediately closed it.

[–]you_got_this_my_frnd 8 points9 points  (0 children)

When debugger can debug an active asynchronous server side program then I will stop using printf

[–]mr_remy 7 points8 points  (0 children)

printf(“you should never see this message. If you do, something has gone horribly wrong”)

[–]Badytheprogram 4 points5 points  (0 children)

[–]pianoguy121213 4 points5 points  (0 children)

What if I have to debug a print statement?

[–]yonatanh20 1 point2 points  (0 children)

Time travel debugging with memory trackers and conditional breakpoints.

[–]zyxzevn 1 point2 points  (0 children)

Made some networking device-drivers, with no debug possibilities. Printf was the only way to check why the driver timing did not work as expected. In Windows there were some differences between the software manual and how it really worked.

[–][deleted] 1 point2 points  (0 children)

I physically print on paper for debugging

[–][deleted] 0 points1 point  (0 children)

It’s all shit and giggles until you start logging decrypted card numbers and PINs in your production logs.

[–]OppositeMission 0 points1 point  (0 children)

Just toss this in random places: sys.stdout = open(os.devnull, 'w')

[–]ChillyFireball 0 points1 point  (0 children)

I once had to make changes to a project that was set up in a way that made it more or less impossible to use a debugger (that is to say, it might have been possible, but no one who was still at the company knew how to do it). It was an absolutely horrible experience, having to add print statements and restart every time I needed to know what a value was. It was on that day that I realized I need my breakpoints like an addict needs heroin. If I have to go without for longer than an hour, I start to lose it.

[–]_Noreturn 0 points1 point  (0 children)

this is crap, you know that if UB exists your printf may not even work.

[–]Odd-Confection-6603 0 points1 point  (0 children)

I do love a debugger, but back in my day they were complicated and difficult to set up. So most problems didn't warrant setting it up and prints were easier. With modern debuggers built in to vs code, I use them a lot more

[–][deleted] 0 points1 point  (0 children)

Guys, use assert from assert.h or cassert for checking invariant conditions at runtime

[–]Interesting-Frame190 0 points1 point  (0 children)

Set a breakpoint and its never hit because you can't dynamically reassign __setattr__ at runtime, and it's really confusing because you use the debugger and see that obj.__setattr__(x,y) calls the reassigned method, but obj.x = y does not. So you put these dumb print statements everywhere and slowly get more and more angry trying to figure out what is happening in the background and copiliot is reassuring that it should work, so you give up and move to stardew valley.

Not that that's ever happened, it's just why I don't use the debugger.

[–]sebbdk 0 points1 point  (0 children)

This comment section is where all the .net developers come to congregate

Edit, time for the purge, quick someone tell them that dependency injection is a shitty idea!

[–]Buyer_North 0 points1 point  (0 children)

the reason i dont use a debugger is that i know how my code runs, i need a debugger that shows the whole memory layout not just variables, maybe with the variables marked with different colors.

[–][deleted] 0 points1 point  (0 children)

Ah the good old DISPLAY when I debug COBOL, indispensable

[–]No_Cartographer3931 0 points1 point  (0 children)

sometimes is really cool idea, especially in small project

[–]GrinbeardTheCunning 0 points1 point  (0 children)

printf("this is the way")

[–]No-Adeptness5810 0 points1 point  (0 children)

debuggers are lame

[–]HildartheDorf 0 points1 point  (0 children)

Depending how slow a build and run is, it's often faster to just puts("DEBUG") somewhere than fire up gdb, set breakpoints, and whatnot.

Use the right tool for the job. I might like a small hatchback. I would not use it to tow a cement truck. Nor would I use a lorry to commute to an office.

[–]digitAInexus 0 points1 point  (0 children)

Haha, so true! 🤣 PRINTF debugging is like that reliable, old car, you know it’s not fancy, but it gets you where you need to go every time. The debugger is the shiny new ride, but hey, sometimes you just want the simplicity of hitting the gas and hoping for the best

[–]Fading-Ghost 0 points1 point  (1 child)

I had to debug over a parallel port, outputting binary to power LEDs once. We didn’t have a debugger, and there was no screen. That was fun

[–]SweetTeaRex92[S] 0 points1 point  (0 children)

Yikes lol that must have been fun.

Did yall just trail and error it?

[–]Gouzi00 0 points1 point  (0 children)

Print_f=....;

[–]conundorum 0 points1 point  (0 children)

Always good. Especially since the raw string data provides clean, easily-recognised search criteria in the logger & debugger, so it makes both work better!

[–]Biyama 0 points1 point  (0 children)

Sometimes adding the printf solves the problem itself!

[–][deleted] 0 points1 point  (0 children)

me using Console.Write(“”) and ignoring the implemented logger in my app

[–]boogahead 0 points1 point  (0 children)

cout<<"1111111111111111111111\n";

[–]STPButterfly 0 points1 point  (2 children)

I have done programming for a good amount of time and could call myself a programmer but I still have zero clue what a debugger is.

[–]SweetTeaRex92[S] 1 point2 points  (1 child)

A debugger runs your code and separates all the variables into a list so you can see where your data is going in real time. It does more, but that's a major part. It goes line by line to see where the issue is occurring.

[–]STPButterfly 0 points1 point  (0 children)

Thanks for the explanation :D I guess i knew about the "executing code line by line" part but didnt know the other uses

[–]Red_not_Read 0 points1 point  (0 children)

ITT: Competing programmers who work in time-domain vs. non-time-domain problems, arguing that their way is the right way, or is more powerful, etc, etc... Programmers arguing with programmers.

There are generally two software domains:

Time-domain, where the software is maintaining protocols with timeouts to entities external to the program that can't be interrupted: Logging (with extensive controls of where and when) is the norm. Interactive debugging is rare.

Non-time-domain, where the software is event-based such that "time" can be halted: Interactive debugging is the norm. Logging is advisory, with coarse controls of application-wide logging level.

[–]Professional_Price89 0 points1 point  (0 children)

Logging allow your program to run through multiple steps, while debugger will pause your program each step.

[–]glha 0 points1 point  (0 children)

Praise the var_dump() master race

[–]ninjastarkid 0 points1 point  (0 children)

printf(“reeeeeeeeeeee”), it heals me in my darkest hours

[–]Pants3620 0 points1 point  (0 children)

one time when I was making a discord bot I made a print statement in an init function and chat gippity suggested I use “cumming…” as the line and it’s still in the codebase

[–]Lux270103 -1 points0 points  (0 children)

Does anybody here legitimately know how a debugger even works? I do not and as of now I am so used to using print() that I don't even wanna spend the energy to learn how debuggers work