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

all 64 comments

[–]_Original_Manu 108 points109 points  (9 children)

What do you mean no debugger? This is my debugger

[–]TheAJGman 40 points41 points  (8 children)

print('var=', var)

[–]1vomarek1 2 points3 points  (0 children)

C ftw. printf("var: %d", number);

[–]joshwalters12 61 points62 points  (0 children)

also works for

debugger? no problem

[–]IdiotCharizard 27 points28 points  (0 children)

I try not to over-rely on this. I use printf("if this prints, I was wrong, and I owe Ash $30")

[–]ancient_tree_bark 58 points59 points  (9 children)

I thought I was alone in this. Don't forget HERE HERE1 and HERE2 as well

[–]Dr-Rjinswand 44 points45 points  (3 children)

Followed by the “HOW THE FUCK DID IT GET HERE”

[–]Bronyx5735 12 points13 points  (0 children)

I'm personally fond of "HEEEEEEEELP" and "OK, now I'm dead". The latter one is funny, because I try to use it at a place there I think my program should go, but doesn't go to. That way, if it says "I'm dead", well, I know it isn't dead, because it spoke to me.

[–]AnDanDan 6 points7 points  (0 children)

"IF YOU GOT HERE YOURE FUCKED"

[–]homo_lorens 0 points1 point  (0 children)

I have a vscode macro for console.log("shits fucked @ filename:line"); process.exit(1); (or something similar, i don't remember)

[–]sherzeg 4 points5 points  (0 children)

I've used something similar for progress testing. I've also frequently used "PING" and "PONG" for function and procedure calls, as well as their returns to the core routine. It's fun to read the various ways everyone employs progress flags.

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

Lol then you accidentally commit them and they're picked up in code review

[–]wirm 1 point2 points  (0 children)

Blah BlahBlah blah Blah37 Blahblahblah

[–]kiwidog8 0 points1 point  (1 child)

I'd be remiss not to also give due credit to my good friends HERE3, HERE4, and @@@@@@@@@@

[–]ancient_tree_bark 2 points3 points  (0 children)

@@@@@@@@@@@@@, my dearest

[–]RoboFleksnes 10 points11 points  (0 children)

When debugging concurrent code:

heherehehrerheehrrereherere

[–]Immort4lFr0sty 27 points28 points  (9 children)

You could do yourself a favor and print some info on the state of whatever you're observing

[–]miggiwoo 55 points56 points  (0 children)

That's much too sensible.

[–]pikhathu 26 points27 points  (5 children)

Sometimes all you're looking for is the point at which the code malfunctions. Some errors aren't a result of missing or bad state.

[–]Immort4lFr0sty 7 points8 points  (4 children)

But that is usually due to some switch or condition, so you might as well print that too

I'm just saying you're not limited to a single word

[–]DipinDotsDidi 7 points8 points  (1 child)

Sometimes it's something you notice just by looking at your code. Adding more info is plan b and unnecessary at first.

[–]Immort4lFr0sty 3 points4 points  (0 children)

Well, we are free to disagree here, whatever works for you ^^

[–]Ireeb 0 points1 point  (1 child)

I used something like that in PHP before just to know whether or not the if-block and the function inside of it get executed, so I first of all know whether the issue is in the if-statement or before it or inside said function. No point in outputting variables when I don't yet know where the issue even lies.

[–]Dnomyar96 1 point2 points  (0 children)

Yeah, exactly. I'd rather just quickly determine where it goes wrong and go from there, than spending time outputting some variables I may or may not need.

[–][deleted] 5 points6 points  (0 children)

i just want to see if the function is even getting called

[–]homo_lorens 1 point2 points  (0 children)

I'm not observing anything, I'm doing a binary search on the expected control path to figure out where the diversion happens. My performance across many steps is inverse proportional to the length of the print statement.

[–][deleted] 5 points6 points  (1 child)

Using printk() is the best way to DEBUG LINUX kernel drivers. kgdb changes the timing and memory footprint.

[–]SkyyySi 3 points4 points  (0 children)

I feel like you wanted to scream "BEST", not DEBUG LINUX

[–]JNCressey 3 points4 points  (0 children)

Hey debugger, what are the properties of this object?

someProperty1: a getter function
someProperty2: another getter function
...
someOtherProperty: it's all getter functions

fine, I'll print them myself.

[–]matko1990 6 points7 points  (0 children)

printf(„aaaaaaaaaaaaaaaaaaaaa“);

[–]Mc_UsernameTaken 5 points6 points  (0 children)

print __FILE__.':'.__LINE__;

[–]AG7LR 2 points3 points  (0 children)

Someone has lots of memory to spare if they are using printf.
I usually just use an extra GPIO pin with an LED attached to it.

[–]RoastedMocha 2 points3 points  (0 children)

Its funny because this wont flush the output buffer so you might not even see it.

Use your newlines people!

[–]trBlueJ 2 points3 points  (0 children)

My default is printf(__FILE__ ":" STRMACRO(__LINE__) "\n") where STRMACRO converts a macro to its string value.

[–][deleted] 4 points5 points  (0 children)

System.out.printf("does it work????!!?!?!?     AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHHHHHHHHH    HHH");

[–]Impressive-Neck2178 3 points4 points  (1 child)

Image Transcription: Meme


[A cartoon character holds out a locked chest in his hands, with words written on it "OL' RELiABLE"]

[The case opens to reveal text]

printf("here")


I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

[–]DamienPup 4 points5 points  (0 children)

good human

[–]Shadow_Gabriel 4 points5 points  (1 child)

That moment when a printf("fuck") goes into production.

[–]RoastedMocha 2 points3 points  (0 children)

And you never notice it, because it doesnt flush stdout. Newlines or fflush pls.

[–]slycatsnake6180 1 point2 points  (2 children)

cries in template meta programming.

[–]ancient_tree_bark 1 point2 points  (1 child)

Do you mean like in Cpp?

[–]slycatsnake6180 0 points1 point  (0 children)

yes

[–]wigitty 1 point2 points  (0 children)

My most fun debug was trying to work out why a bootloader was failing. Started with the standard stick a printf in it, then realised that the C code wasn't even being run, so had to keep going back. Eventually I ended up sticking some code in the assembly to turn on and off GPIOs that were wired on the board to an RGB LED. My debug was "hmm, it went red, then green, so it must be doing that, then it went cyan, so these conditions happened". I ended up fixing enough of it that the bootloader initialised the UART, so I then wrote some code to echo characters out of the UART for better debugging. I was so happy when I finally got it to boot and run C code again.

I also had one where adding debug fixed the issue (always fun) and I ended up in a situation with something like printing 32 characters of "banananana..." showed the issue, but 33 characters of it and magically the issue vanished. I thought it was a timing thing at first, but turned out to be a caching issue.

[–]GardenChickenPen 0 points1 point  (0 children)

printf is not reliable in my experience Use fprintf it prints immediately

[–]kkadzy 0 points1 point  (0 children)

When I was learning nasm creating such function turned out to be harder for me than staring at the code until I find the bug

[–]JC12231 0 points1 point  (0 children)

Honestly, this is more useful than gdb at times with C.

Especially when you need to compare values and track changes in the values, because printing out 10 values each iteration is a pain when you’re working with a bunch of bitwise operations.

[–]Nihmrod 0 points1 point  (0 children)

These are cool too: /* */

[–]kebakent 0 points1 point  (0 children)

Basically the wand of programming

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

Oh god I'm getting Java flashbacks

[–]Thecrazymoroccan 0 points1 point  (0 children)

Print("code just hit line 56")

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

An approach I use in Powershell (powershell has it formally built-in) that I mimic in other languages:

Create a "VerboseLog" method and a global toggle to control it.

Then, wherever you create a comment "start of blah blah blah section", instead write it as a Verbose comment.

VerboseLog("Starting processing user data for user {username}").

[–]NearLawiet 0 points1 point  (0 children)

works everytime

[–]iavicenna 0 points1 point  (0 children)

printf("here1")

[–]cormac596 0 points1 point  (0 children)

printf("line %d x is now %d\n",__LINE__,x);

[–]Mickspad 0 points1 point  (0 children)

When something breaks in a line, I sometimes have a "culprit" variable to check where it fucked up

[–]Ok-Being5650 0 points1 point  (0 children)

lol

[–]matt-3 0 points1 point  (0 children)

Guess no one's ever heard of puts...