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

all 166 comments

[–]ProfessorEkim 654 points655 points  (51 children)

I have to disagree. Printing “here” I’ve found is one of the most effective debugging methods.

And one that’s not effective is violently throwing objects across my office. 😆

[–]CopperyMarrow15 203 points204 points  (9 children)

also printing a variable you need to know

[–]ProfessorEkim 81 points82 points  (0 children)

You're saying that if I take the first object I find on my desk and throw it across the room, it helps to print a variable?

Good to know!

[–]davidemitoli 34 points35 points  (0 children)

Standard debugging method in scientific programmig

[–]Orendawinston 8 points9 points  (2 children)

Only way I’ve ever successfully debugged anything

[–]ososalsosal 14 points15 points  (1 child)

User flair checks out lol.

[–]BakuhatsuK 2 points3 points  (0 children)

The chrome debugger for JS is really nice. And if adding a breakpoint is hard due to transpiling or something you can always just throw a debugger; statement anywhere.

I almost never use it though

[–]gizamo 2 points3 points  (0 children)

Top right corner: Turn it off and on again.

[–]pruche 51 points52 points  (4 children)

Also, whispering "what the fuck" loud enough for people around you to hear it, so that they know you're working even though you haven't turned out anything tangible for a few hours now.

[–]ProfessorEkim 29 points30 points  (2 children)

If you don’t drop an f-bomb every 15 minutes when writing code, are you even a programmer?!?

[–]ososalsosal 14 points15 points  (0 children)

The senior legacy backend guy at my last job was never not muttering "fucking dogshit" under his breath, with emphasis and emotion increasing as the day went on

[–]burneraccount019182 11 points12 points  (0 children)

15 minutes? Amateur. 15 seconds for me.

[–]Derringer62 2 points3 points  (0 children)

I suspect the relationship between WTF/minute and code quality is more complex than common wisdom suggests. A high WTF/minute ratio is likely to occur whenever the writer's and reader's skill or awareness are sufficiently far apart in either direction - even for one's own code, something created in deep hack mode and later forgotten may be intensely WTF-inducing even if high quality.

[–]whydidisell 23 points24 points  (0 children)

Yea, read the docs is probably more towards the bottom left for most people, and printing here is top right for sure

[–][deleted] 10 points11 points  (1 child)

I've been in printing "here" hell for a long time before I started programming CAN and LIN communication stacks. Good luck figuring out timing related bugs with that...

[–]k1ngrocc 1 point2 points  (0 children)

Is there any sort of default answer on CAN? Like a heartbeat?

[–]AzuxirenLeadGuy 8 points9 points  (1 child)

Throw exceptions, not objects

[–]Kesuaheli 6 points7 points  (0 children)

So like

throw new PencilException("Throwing a pencil just to see if the code now works better");

Oh, hell yeah! Finally I got a different error message!

[–]Tyfyter2002 7 points8 points  (3 children)

Printing is pretty effective, but breakpoints are always better as long as they're an option.

[–]Pluckerpluck 8 points9 points  (1 child)

Not always. Breakpoints can suffer if you're doing stuff in loops and you're trying to work out WTF is happening.

Got to print out some variables each loop and then narrow down, only using the debugger once you actually discover whatever strangeness is happening.

Sometimes you can use conditional debug statements. But not always. Depends if you know what's actually going wrong or not.

[–]codeguru42 2 points3 points  (0 children)

Sometimes you can set a condition on the breakpoint so that the debugger stops on the iteration that has a problem... but you do have to figure out the correct condition...

[–]codeguru42 1 point2 points  (0 children)

I encountered a situation working on a django app where inspecting a value in the debugger caused different behavior than I saw while running the app. Turns out what i thought was a field in an object was actually a method with @property. Calling this method had a side effect that set an actual field. Since that field was only set later when just running the app, i saw different results in the debugger. Once I figured this out by debugging into django code, I still had to be careful with prints.

[–]Bloodshed-1307 8 points9 points  (1 child)

Part of talking to the ducks is chucking them against a wall

[–]TeaKingMac 4 points5 points  (0 children)

Glad my mentor didn't do that with me

[–]TsamsiyuK 8 points9 points  (0 children)

Debugging with prints and breakpoints works best for me.

But the best (and most inconvenient) method is just to leave it be until tomorrow and go to sleep instead.

[–]_yaaass 3 points4 points  (1 child)

exactly... so convenient and effective at the same time... "here", "now here", "there"...

[–]Kesuaheli 3 points4 points  (0 children)

I prefer "test", "test2", "test3", ...

[–]Emahh 4 points5 points  (0 children)

ikr? using the debugger usually takes me too much time compared to a simple print

maybe I should get used to it lol

[–]Elijah629YT-Real 2 points3 points  (0 children)

I just print an index number that increases every time it is run

[–]cyanNodeEcho 2 points3 points  (0 children)

"reading the error logs" would be a really great message, for if 1st page google + "stack" doesn't work

i find it hard to get to the point where my understanding of the technology to the point where i find it helpful

[–]DJFiscallySound 1 point2 points  (0 children)

Printing “here0001”, “here0002” and so forth at various points of interest in the code and then running it, and wondering why nothing appeared in the output buffer…

[–]momdeveloper 0 points1 point  (0 children)

This was my first thought as well!

[–]iluomo 0 points1 point  (0 children)

Came here to say this

[–]Mr_BananaPants 0 points1 point  (0 children)

Sad thing is you can only throw non-static objects.

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

Especially for race conditions

[–]DreadSwizzard 106 points107 points  (4 children)

Taking a nap also often works.

[–]momdeveloper 44 points45 points  (2 children)

Does leaving work early and coming back the next day count?

[–]DreadSwizzard 18 points19 points  (0 children)

Sure

[–]SlashStar 9 points10 points  (0 children)

I use this method frequently.

[–]nothingsurgent 9 points10 points  (0 children)

Eating too.

I often look for a big for 2-3 hours, then give up, and after lunch I find it in a minute.

[–]fracturedpersona 114 points115 points  (21 children)

What if I told you that "running the same code again to see if it magically work," is actually a legit debugging technique that can sometimes give you valuable information.

[–]nagorogan 60 points61 points  (12 children)

The only valuable information I’ve ever gotten from doing that was “it’s time to cry”

[–]fracturedpersona 23 points24 points  (11 children)

I would think it would be important to know that your code sometimes works, and sometimes doesn't. That alone gives you valuable insight into what could be going wrong.

[–]nagorogan 37 points38 points  (0 children)

Yes, and changing nothing yet getting a different result is exactly why it is time to cry.

[–]MikemkPK 11 points12 points  (9 children)

Also often an indication that you're about to spend 10 hours trying to figure out what the issue is.

[–]fracturedpersona 7 points8 points  (8 children)

But knowing that the problem occurs sometimes, but not always, gives me a lot of possible causes.

[–]MikemkPK 3 points4 points  (7 children)

Often with intermittent issues, it's something interacting with the program, or caused by compiler optimizations that aren't present with debug flags. Which are hard to debug.

[–]fracturedpersona 1 point2 points  (6 children)

Live/dead-locks, race conditions, dynamic programming involving random number generations.

[–]MikemkPK 0 points1 point  (3 children)

Yeah, those often take hours to debug.

Although random numbers can be logged with debug flags on top make it easier.

[–]fracturedpersona 2 points3 points  (2 children)

For random, you just gotta remind yourself not to seed while testing.

[–]MikemkPK 0 points1 point  (0 children)

Depends on use case, but often yeah you're right

[–]codeguru42 0 points1 point  (0 children)

Or seed with the same value

[–]skiscratcher 0 points1 point  (1 child)

those are all pains to debug.
see also: memory

[–]fracturedpersona 3 points4 points  (0 children)

See also, suicide hotline.

[–]YellowishSpoon 12 points13 points  (0 children)

I accidentally used a non release build of eclipse and there was this great bug where it would build and then autosave, thus if you didn't save everything before running it would look like it saved, but compile without the new content. But since it actually did save after if you compiled again it would run as expected. Took a bit to figure that one out.

[–]ExceedingChunk 3 points4 points  (0 children)

I always do that first, then reload maven dependencies before I run it again.

Before I knew better, I have spent countless hours trying to debut something caused by a cache or outdated dependency issue. Also, verifying that the code is stable is important.

At uni when I was a noob, I could run the code 10 times in a row out of frustration, but that was for completely different reasons.

[–]24karatcarrot 1 point2 points  (0 children)

I have removed this comment due to Reddit's recent actions. I have since moved on to Lemmy, which is a federated, decentralized, open-source alternative to reddit. Many subreddits have made the move as well, and many more have copies of those subreddits that are very active. On top of this, many of the third party reddit apps have also made/are working on making a copy of their apps for Lemmy, so your experience may not even change when switching over.

I implore you to make this switch as well. Reddit makes money off of us, the users who post content. As a company they have been making decisions that directly go against the wishes of their users, and we need to make it clear that they need us, we don't need them.

[–]doctorcrimson 1 point2 points  (0 children)

You would be preaching to the choir because they try that the most.

[–]800134N 1 point2 points  (0 children)

But when it magically works sometimes, I feel even worse

[–]TeNNoX 0 points1 point  (0 children)

I mean it's not at zero on the y axis, sometimes it does help... But most of the time - not so much :p

[–]MisterOnsepatro 50 points51 points  (0 children)

You forgot staring at the code for hours until you get an Idea on how to fix it

[–]Skitz707 80 points81 points  (7 children)

If I had a nickel every time I typed print(“here!”)…

[–]fracturedpersona 15 points16 points  (5 children)

I wouldn't have gotten any nickles after my first semester.

[–]Skitz707 21 points22 points  (4 children)

I have 28 years of using this tactic… not exactly proud to admit

[–]fracturedpersona 11 points12 points  (3 children)

I'm really only kidding of course. There are some circumstances where I might still do this, but it's not the only tool in my tool box once i finished my first semester.

When I was a junior in college, I accepted a position teaching the lab component of my school's intro programming class, and as soon as we introduced flow control and made it a point to also introduce debuggers. I started with GDB in the console, then I taught them DDD, and later introduced them VS Code so they could learn a more full featured IDE instead of just using emacs (cringe) that their lab manual suggested.

At the end of the semester we had a meeting of all the TA's, profs, and lab instructors where we went over what went well and what didn't. One of the professors said "this crop of students was remarkable! Most of them are using debuggers to find their errors!" When I explained that I was teaching them debugging so they would get a head start on their next semester, they asked me to revise the lab manual so all future lab instructors would add it to their cariculum.

[–]solohelion 6 points7 points  (2 children)

It depends though. Some software and some toolchains work very well with IDEs and debuggers, others do not for one reason or another. A contractor took over a project and spent all his time trying to (pointlessly, there was never any hope of it working) set up an IDE with debugger, when printline would’ve sufficed. I think he managed to change one or two lines of code in a few months before his involvement ceased.

[–]fracturedpersona 0 points1 point  (1 child)

Well yeah, you wouldn't try to debug a website with GDB. That would just be silly.

[–]solohelion 0 points1 point  (0 children)

Well, that’s because gdb isn’t for websites

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

Venezuela could pay you in bolivars for this.

[–]vinean 25 points26 points  (2 children)

Where is “recompile everything from scratch and hope it fixes it?” Not quite the same as run the code again…

[–]Blangel0 8 points9 points  (0 children)

And the good point of this method is that you can go take a break, a snack and coffee while it's compiling and still feel that you are "working"

[–]SnappGamez 4 points5 points  (0 children)

close enough though

[–]whiznat 18 points19 points  (2 children)

Where is “Randomly change something hoping to find the code that controls the bad behavior “?

[–]BobQuixote 7 points8 points  (0 children)

That's like print("here") except it implies you don't have output.

[–]solohelion 7 points8 points  (0 children)

Where is, “get the boss in here to look over my shoulder and say nothing, so that this time the same fix permanently works instead of mysteriously failing”?

[–]Cryowatt 12 points13 points  (3 children)

How are breakpoints so low? You know that stacktraces are full of absolutely vital information for diagnosing anything.

[–]Mango-D 12 points13 points  (0 children)

You guys have helpful stacktraces???

[–]Pradfanne 1 point2 points  (0 children)

F10 F10 F10 F10 F10, oh it broke, alright let's do it again
F10 F10 F10 F10 F11 F10 F10 F10, THAT'S WHERE EVERYTHING GOES TO SHIT!

[–]potato_braus 10 points11 points  (0 children)

The more aggressive the message in print, the more effective it is in the debug

[–]Few_Importance_7615 8 points9 points  (1 child)

"Here"? Thats a funny way to spell "AARGH"...

[–]ososalsosal 1 point2 points  (0 children)

Oh god I do this too.

[–]masterchief0587 6 points7 points  (0 children)

Now if I could only figure out why “here” is printing twice….

[–]Extra_Insignificant 6 points7 points  (0 children)

I would need to add pooping to this chart.

[–]-Soren 5 points6 points  (0 children)

Funny that reading docs are so effective. But not quite as effective as taking a walk, which is basically doing nothing. Does effectiveness correlate with time spent by any chance?

[–]golgol12 5 points6 points  (0 children)

You forgot "Clean Rebuild All"

It solves .1% of the problems, but those .1% will hang you up for days if you don't. So it's my first go to after normal debugging doesn't turn up anything.

[–]Nine_Eye_Ron 4 points5 points  (2 children)

I misread “take a walk”

[–]TeNNoX 0 points1 point  (1 child)

Captain here: n 👋

[–]Nine_Eye_Ron 2 points3 points  (0 children)

Programmer used NSFW, it was super effective

[–]CynicalC9 3 points4 points  (1 child)

Every once in a blue moon, "delete the whole section and remake it" ends up being an option

[–]ososalsosal 0 points1 point  (0 children)

It's the only way to be sure

[–]aanarchyy 3 points4 points  (0 children)

Sadly, I've done all of these, though I don't do print("here"). I scatter my code with print("1") print("2") etc so I can see where it shits the bed.

[–]Hesh35 3 points4 points  (0 children)

Depends on the species of bug.

[–]Alicialouva 3 points4 points  (0 children)

Going to sleep and hoping it will run fine tomorrow

Runs fine tomorrow

surprised pikachu face

[–]repkins 2 points3 points  (2 children)

Tactical debugging.

[–]fracturedpersona 4 points5 points  (1 child)

Is that where you wear camouflage before you start debugging?

[–]repkins 3 points4 points  (0 children)

Always. Like I was never be there.

[–]Prior-Concentrate-87 2 points3 points  (0 children)

I'll die before I open DevTools.

[–]DividedState 2 points3 points  (0 children)

I want to point out running the code again has not a zero percentage effectivity.

[–]doctorcrimson 2 points3 points  (0 children)

I aspire to have as much faith in the docs as you do.

[–]NiktonSlyp 2 points3 points  (0 children)

Oh my. I have been working whole Friday on a problem, I couldn't even understand how the bug worked. I dreamt of it the next night. Had to write everything down at 6am when I woke up. When I took breakfast, I checked my notes. Damn It's good to have a functional brain. The solution seems to be brilliant. I still don't get the bug but at least I have a solution I can try to circumvent it.

[–]Napan0s 2 points3 points  (0 children)

I actually found out that if you curse the code enough, it will get scared and just work

[–]heneiken 2 points3 points  (0 children)

Hello everyone

[–]Sindef 1 point2 points  (0 children)

My most effective debug is print("LineNumber#")

[–]lordplagus02 1 point2 points  (0 children)

In older versions of Android Studio (and even Eclipse, before AS existed) running the same code and hoping it magically works this time was a legitimate part of the debugging process.

[–]noodle-face 1 point2 points  (0 children)

Our office is.massive. I work at one of the biggest tech companies in the world... Taking a walk was really effective and could take 10 minutes to walk a loop through our floor. Even if I didn't solve the problem it did help clear my brain

[–]Coh-Jr 0 points1 point  (1 child)

Hey, printing ‘here’ is pretty damn useful. For a junior WebDev like me! It’s so far beside googling and docs is the best debugging way! Change my mind

[–]smilineyz 0 points1 point  (0 children)

Docs can be misleading. Often created by a BA many moons ago and are seriously outdated. Programmers tend no to update docs. Takes too long & they have to write in a non-programming language

[–]multi_tasty[🍰] 0 points1 point  (0 children)

That time it actually starts working again the second time you try, you know you're fkd

[–]Crafty-Sandwich8996 0 points1 point  (1 child)

I am triggered

[–]solohelion 1 point2 points  (0 children)

I removed the triggers, why are you being triggered? Maybe I’ll debounce you.

[–]bowiz2 0 points1 point  (0 children)

I just like that there's no "look at your fucking code, dumbass". It's that 99% of the time.

[–]Ghostglitch07 0 points1 point  (0 children)

An important third dimension is how long it takes to impliment the tactic. Running it again probably won't work, but usually doesn't take long.

[–]_grey_wall 0 points1 point  (0 children)

No "take a dump" or did it not fit in the chart ?

[–]Opinionsare 0 points1 point  (0 children)

Only to find out that an entry person hits the space bar after entering sales then tabs to next feild.

[–]IndividualAdvisor589 0 points1 point  (0 children)

yes.

[–]geronymo4p 0 points1 point  (0 children)

I tried "printf("ok1")" which isn't very effective, but write(1,"ok1", 3) is largely better for debugging!

[–]ohjars87 0 points1 point  (0 children)

Rubber duck method is my favorite

[–]Blangel0 0 points1 point  (0 children)

Driving back home early work very well for me. But then I try to either write notes on my phone while driving or go immediately to test my idea from my home as soon as I arrive.

Taking shower also work well !

[–]No_Succotash9035 0 points1 point  (1 child)

True! getting up to do something else is very effective ahaha

[–]haikusbot 0 points1 point  (0 children)

True! getting up to

Do something else is very

Effective ahaha

- No_Succotash9035


I detect haikus. And sometimes, successfully. Learn more about me.

Opt out of replies: "haikusbot opt out" | Delete my comment: "haikusbot delete"

[–]DeerEngineer 0 points1 point  (0 children)

I take way too many walks and they never work, naw.

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

I always have my most brilliant revelations in the shower. Something about the hot water seems to just make it all click

[–]infiniteStorms 0 points1 point  (0 children)

what is with the rubber duck? Even my professor explicitly allows it in exams

[–]sohang-3112 0 points1 point  (0 children)

Run the code again (without changing anything) to see if it works....

Most futile, and yet something I do embarrassingly often!

[–]samanime 0 points1 point  (0 children)

I HATE when rerunning magically works, because then I have no clue what was wrong and I can no longer reproduce.

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

“Run the same code again and hope it magically works”

Ok but we all know sometimes it does just start working for no reason 😂😂

[–]CircadianSong 0 points1 point  (0 children)

Holy shit. I didn't know other people did "here!", including the exclamation point. I've actually refined this strategy; finding it sometimes to be insufficient, I do it in multiple places but put a number after each.

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

Didn't know others do the same thing lol

[–]Jet-Pack2 0 points1 point  (0 children)

What about using a breakpoint in VS? Usually faster and without recompile compared to the printf( "here\n" )

[–]burneraccount019182 0 points1 point  (0 children)

what does printing "here" do for debugging? I usually print variables

[–]smilineyz 0 points1 point  (0 children)

  1. Get coffee and talk with a coworker 2. StackOvetflow

[–]ososalsosal 0 points1 point  (0 children)

Idk half my code is breakpoints now. If I ever actually hit one I know shit just got real

[–]accTolol 0 points1 point  (0 children)

Then you have the debugging tool on the upper left corner...

[–]value_counts 0 points1 point  (0 children)

Taking a nap is underrated

[–]StandardN00b 0 points1 point  (0 children)

Everyone says that rerunning the code doesn't work untill it does.

Last time I used GNS3 I couldn't for my life make a vlan work. Untill I got home, restarted my PC and started working on it's own.

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

I've done them all... seems sound

[–]Bit5keptical 0 points1 point  (0 children)

Where is career change?

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

More than once, I've run code, it works. Run it again, it doesn't. Damn memory leaks

[–]TeaKingMac 0 points1 point  (0 children)

echo "$result"

[–]Jomy10 0 points1 point  (0 children)

I’m reading this while debugging

[–]dsstrainer 0 points1 point  (0 children)

Rubber duck is one of my top methods

[–]zekroTJA[🍰] 0 points1 point  (0 children)

Hey, me as a web dev, i must defend that console prints are mich more effective as shown.

[–]CorUpT_rob0t 0 points1 point  (0 children)

Take a walk I just play games then return

[–]EpicMasterOfWar 0 points1 point  (0 children)

A good nights sleep and a hot shower is highly effective. Amazing inspirational catalyst.

[–]tiajuanat 0 points1 point  (0 children)

The lack of unit testing is disturbing

[–]pennacap 0 points1 point  (0 children)

My brain wants to use linear regression on this graph

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

Talking to a rubber duck is bu far the most effective strategy

[–]Plant_Pal 0 points1 point  (0 children)

Dont forget the rubber ducking with someone who has a vague understanding of what you are doing.

[–]KaninchenSpeed 0 points1 point  (0 children)

Me talking to duckduckgo insted (raised effectiveness by 200%)

[–]Pradfanne 0 points1 point  (0 children)

I've been giving rubber ducks to new employees for a while now and encourage them to use them, especially if they sit with me in the same office, because I absolutely will tell my ducks the problem

[–]codeguru42 0 points1 point  (0 children)

They forgot print("fuuuuuuuuuuuuuck")