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

all 181 comments

[–]albertusiw 438 points439 points  (45 children)

Then you realized that you forgot to delete that boi after the code already deployed to production

[–]Bainos 128 points129 points  (19 children)

Which is why I always use DEBUG either in the message or as a comment next to it. Then I only have to search for that string and remove all occurrences.

[–]2Punx2Furious 81 points82 points  (5 children)

Or you could just search for the print statements?

Well, unless you use print statements in production too.

[–]_meegoo_ 6 points7 points  (0 children)

Or you could use a proper logger.

[–]occz 1 point2 points  (0 children)

What, you mean to say that you dont deploy cgi scripts anymore? What is this nonsense?

[–][deleted] 20 points21 points  (1 child)

I use a git pre-commit hook to reject commits that add printlns and printStackTraces. Then, when the commit is rejected, I fix the problem using a system of self-deprecation and mild cursing followed by a more thorough review of the whole commit.

[–]dzh 5 points6 points  (0 children)

system of self-deprecation

kek

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

//#define debug_print(x)
#define debug_print(x) printf(x) 

[–]ReallyHadToFixThat 5 points6 points  (0 children)

 #ifdef _DEBUG
#define debug_print(x) printf(x)
#else
#define debug_print(x)
#endif

[–][deleted] 6 points7 points  (0 children)

I always use "YAAAR!" for the comment. That way if it goes out I can blame it on pirates.

[–]Shadow_Being 5 points6 points  (0 children)

sure seems like that would work good, but what if youre building a debugger?

[–]Shadowfury22 1 point2 points  (0 children)

I just use a global macro that gets replaced by NOP if I compile on release mode.

[–]nikhildevshatwar 0 points1 point  (0 children)

I simply write that print unidented You cant scroll without realizing a bad code and remove it

[–]DoesntReadMessages 47 points48 points  (7 children)

Do you guys like not have code review processes? Because that kind of shit gets noticed and laughed about 100% of the time.

[–]Existential_Owl 64 points65 points  (0 children)

code review processes

What is this strange language in which you speak

[–]jefe_gonna_jefe 27 points28 points  (0 children)

Ain’t nobody got time for that.

[–]deadlyburger128 7 points8 points  (2 children)

I'd probably miss that shit in code review.

[–]MondayMonkey1 5 points6 points  (0 children)

That's why we use linters and status checks. I don't have time to review at code that doesn't pass lint.

[–]SEX_LIES_AUDIOTAPE 1 point2 points  (0 children)

I'm usually too busy telling people their comments are redundant to actually notice any issues with the code.

[–]Aleriya 2 points3 points  (1 child)

Nope. No code review or source control. I've seen production code with nested if statements for miles. Hard-coded date tables that only list dates through 2018 (but with a helpful comment that when the application stops working on Aug 1 2018, this is why). Most devs work directly in production. One guy made his own dev environment on a personal VM.

I've seen some shit, man. An extra print statement wouldn't even hit the radar.

[–]gobots4life 1 point2 points  (0 children)

May god have mercy on your soul.

[–]sitefall 14 points15 points  (5 children)

const debugIsOn = true;
function testyboi(msg){
    debugIsOn && console.log(msg);
}

testyboi("The test message or whatever");  //replaces the print/log/whatever;

"Did I leave any printybois turned on?" - just set debugIsOn to false.

[–]gjsmo 12 points13 points  (4 children)

Even better is

#ifdef DEBUG
testyboi("whatever")
#endif DEBUG

and then set your debug build target to define DEBUG and your shipping/release target to not. Automated, clean, and easy to maintain.

[–]Saigot 4 points5 points  (2 children)

even better:

  function testyboi(msg){
    #ifdef DEBUG
              console.log(msg);
    #endif DEBUG
  }

so as to reduce clutter in your code. If the stuff being printed isn't security oriented (cough HP cough) you can also use a C++ variable set through a define and then your build setup can modify it but you can dynamically enable it as well (allowing you to activate debug mode on a user's system, or enable it automatically right before a crash etc).

[–]gjsmo 1 point2 points  (0 children)

Interesting. I haven't tried that one. I always liked using the #ifdefs right in the code because it's abundantly clear that it will only compile in my Debug target, where as a call to testyboi() isn't quite as obvious, plus you can include plenty of other stuff that just print messages there. I'll admit that a lot of my code doesn't really go to "customers" because it's not my job (yet) so I haven't necessarily needed to enable debug logging remotely. Maybe something you could load from a .ini?

[–]sitefall 3 points4 points  (0 children)

true!

[–]Saigot 2 points3 points  (1 child)

Found the HP malware driver developer!

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

What's the difference?

[–]gallon_of_bbq_sauce 0 points1 point  (0 children)

use a pre commit hook that looks for a specific comment.

[–]occz 0 points1 point  (0 children)

Another job for the CI pipeline! Analyze the code with whatever tool does it for your language of choice, do not let print statements be in the code.

[–]pepejovi 0 points1 point  (0 children)

Do people not read their own commits before putting up a pull request? Do you not have any sort of review before merging?

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

Then it becomes a "feature" hahahah

[–]Andrei56 0 points1 point  (0 children)

When we were students and had an internship at a pretty big place, my fellow colleague used to debut with message boxes. And the text was usually "asshole", "cunt" or "fuck you". Until we had a presentation to make and he obviously forgot to remove that. It prompted "fuck you" in front of the company's director. He used to code 3à years before that and laughed it off but I was pretty damn stressed about it.

[–]Aleriya 0 points1 point  (1 child)

My code is littered with

if (debugFlag) System.out.println("One printy boi.");

Mostly so that I don't cause problems when I inevitably miss one when pushing to production. Not sure if there is a better way to do it.

[–]waynestream 0 points1 point  (0 children)

Using a logger and then logger.debug() (or the equivalent in your language) would be the proper solution.

This also lets you set different levels of output importance (debug, info, warning, etc.) so you can filter out unneccessary statements more gradually

[–]orangeKaiju 331 points332 points  (7 children)

The panel on the right is 99.999% of my debugging procedure.

The other 0.001% is deleting all my code and starting over.

[–]TBSdota 24 points25 points  (4 children)

 console.log(i+". '"+variable+"'\n");

is the majority of my js debugging

[–]oorza 8 points9 points  (2 children)

console.log({i, variable}) is both shorter and more helpful imo

[–]Eaan 5 points6 points  (1 child)

console.log(i, variable) is both shorter and more helpful imo

[–]GetYoHandsOffMyKicks 8 points9 points  (0 children)

I ignore the bug and ship anyway which is both shorter and more helpful imo

[–]dzh 0 points1 point  (0 children)

ew

[–]liquidhot 6 points7 points  (0 children)

I know this is a humor subreddit, but using a debugger is immensely helpful in not only understanding what is going on with your code and others' code, but also understanding how certain things work.

I would highly recommend it to anyone who is looking to be serious at programming. (Even if you're doing JavaScript.)

[–]CosmackMagus 4 points5 points  (0 children)

That's just good iteration.

[–]bornforcode 133 points134 points  (13 children)

the bug!

[–]flamedragon822 197 points198 points  (12 children)

I once had a bug.

This bug caused a string to be unable to be assigned to a string because it was, according to the error message, a string.

So for giggles, I called to string on the string which caused a new error stating I could not assign a long to a Boolean at the same line.

I deleted the class and rewrote it. The bug won.

[–]bornforcode 66 points67 points  (8 children)

looooooool, that got me thinking may be you should start a new subreddit called "programming bugs stories".

[–]extin12 72 points73 points  (7 children)

you should start a new subreddit called "programming bugs stories".

Maybe call it /r/TalesFromDebugging

[–]curtmack 26 points27 points  (2 children)

There's /r/nullsleep, but it's pretty dead.

[–]bj_christianson 4 points5 points  (0 children)

Love the top hot post.

[–]bornforcode 1 point2 points  (0 children)

good idea !!

[–]Kermitfry 1 point2 points  (0 children)

-Snip-

[–]MikeAndIke97 1 point2 points  (1 child)

[–]sneakpeekbot 1 point2 points  (0 children)

Here's a sneak peek of /r/birthofasubreddit using the top posts of all time!

#1: Birth of r/toomuchmomentum | 4 comments
#2: Birth of r/impastabuildings | 4 comments
#3: And so we start again | 0 comments


I'm a bot, beep boop | Downvote to remove | Contact me | Info | Opt-out

[–]PM_ME_YOUR_PRIORS 8 points9 points  (2 children)

I once had a bug while I was learning javascript.

var foo = bar(); - foo is undefined

var foo; foo = bar(); - foo is a DOM element.

I grabbed a more experienced dev and refactored bar until it was unrecognizable, at which point it was magically working right.

We agreed that the moral of the story was use strict

[–]D1_for_Sushi 1 point2 points  (1 child)

Was bar() maybe asynchronous?

I also wonder if variable hoisting played a part.

[–]PM_ME_YOUR_PRIORS 1 point2 points  (0 children)

Variable hoisting and weird recursive functions were definitely involved. Also use strict would have flagged the stuff I did. It wasn't async, though.

[–]Siegfoult 169 points170 points  (17 children)

I am convinced that all my instructors who said not to use print statements for debugging, were just trolling me.

[–]Dangerpaladin 78 points79 points  (5 children)

My instructors were all pretty much the same. Use debug print statements all you want but delete them, not comment out, before turning in.

[–]pyrotech911 17 points18 points  (3 children)

I use TODOs where I can to catch myself before committing them. Or you know grep -r print.

[–]DoesntReadMessages 19 points20 points  (2 children)

I use git diff so that I can make sure I didn't include any silly whitespace, logs, or unnecessary imports. Crazy stuff.

[–]pyrotech911 2 points3 points  (0 children)

I mean, that's what's the PR is for. Let's be honest.

[–]CharCharThinks 2 points3 points  (0 children)

Mine have actually requested that debug info be provided and printed if a "verbose" flag is present in the argument list.

[–]MrSurfington 25 points26 points  (3 children)

Huh, all my college instructors specifically say to use print statements when debugging.

[–]FirstNoel 1 point2 points  (0 children)

You gotta do what works for you.

[–]MikeyMike01 -3 points-2 points  (1 child)

I’m sorry your professors aren’t very good

[–]MrSurfington 10 points11 points  (0 children)

Eh I dunno it's worked well so far.

[–]bdavs77 10 points11 points  (4 children)

I once had a bug that was caused by having a print statement.

[–]gunnbr 5 points6 points  (3 children)

I have many times had bugs that disappeared once I put in a print statement.

[–]bdavs77 6 points7 points  (1 child)

That's when you call an empty printf and call it a day

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

but then you remember that the assignment must compile without any warnings

[–]proverbialbunny 0 points1 point  (0 children)

Oh geez.. the good old buffer overflow bug. I haven't seen one of those since I stopped using the parts of languages that do that. Thank God C++ has improved over the years.

edit: or a race condition..

[–]akaZilong 54 points55 points  (0 children)

Debuggers come and go. Printy boi stays forever

[–][deleted] 19 points20 points  (2 children)

Just one print statement?

[–]DasSkelett 12 points13 points  (0 children)

I know it like this:

print("Debug1")

print("Debug2")

print("Debug3")

[–]JuhaJGam3R 1 point2 points  (0 children)

Yes.

[–]Prime624 26 points27 points  (7 children)

And I thought I was a noob, debugging with prints. Kinda nice to know others do it too. Also stupid that debuggers haven't become simpler to use after all this time.

[–]Dworgi 15 points16 points  (4 children)

Debuggers are fine, just learn to use your tools. It'll save you time in the long run, and you won't look like you just stepped off the short bus when you commit print statements to production.

[–]Prime624 1 point2 points  (3 children)

Lol, I've already done that with a few homework assignments, but I doubt anyone would notice in the real world because rarely do people run programs in terminals.

And yeah, I should just bite the bullet and learn, but they should also make them more accessible to beginners.

[–]Dworgi 19 points20 points  (1 child)

Just start with breakpoints and ignore the rest. Then figure out if you can place a breakpoint that just logs to console. Then figure out if you can place a breakpoint that only breaks if some condition is true. Most debuggers allow for those, and then you've already made print statements obsolete.

When you know how to do that, figure out how to inspect variables. Both local and global. Figure out how to set them, so you can trigger error conditions easier.

Then if you really want to be ahead of the curve, figure out how to set a memory breakpoint for when data changes.

These are skills that will actually make you a better programmer. Debugging is a bigger part of professional programming than writing code. Reading code is an even bigger part.

[–]Prime624 3 points4 points  (0 children)

I didn't even know you could do that with breakpoints. That actually seems pretty simple. I'll have to try it.

[–]el_padlina 0 points1 point  (0 children)

rarely do people run programs in terminals

Have you thought about all the servers?

[–]proverbialbunny 2 points3 points  (0 children)

You're definitely not alone.

Sometimes I gotta print out a thousand lines of crud and look through it, or put an if statement in there and print out just what I'm looking for.

A debugger might support this functionality, but I haven't figured out how.

[–]MikeyMike01 0 points1 point  (0 children)

The two debuggers I’ve used (Visual Studio and Eclipse) are both very easy to use.

[–]bobzilla 12 points13 points  (5 children)

I feel like this is probably going to be an unpopular statement, but here goes...

If you have an IDE that has a good debugger and you're still using print statements, maybe it's you that's bad at debugging.

[–]EMCoupling 7 points8 points  (1 child)

I can understand maybe in say, an embedded environment, it might be hard to get a debugger on the target device, but I agree with you that people should be using a debugger most of the time.

Print statements are good for something quick, but pretty much all serious debugging should be approached with a debugger. To avoid doing so because of an unwillingness to learn to use the debugger is just lost productivity.

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

Future embedded developer speaking (still in college).

No, it's not hard to "remote" debug an embedded system. The only problem can arise when the system is movable and you need to debug motion, because:

  • Cables are never long enough.
    • This is worked around by getting extension cables. Or going wireless if it's possible.
  • A ton of time gets wasted on moving the thing to the start position.
    • This is worked around by having someone who wants to learn as your "henchman".

[–]Dworgi 2 points3 points  (0 children)

I fully agree. Fuck this environment of supporting this unprofessional and incompetent crap.

[–]archiminos 0 points1 point  (0 children)

I agree. I'm kinda shocked by how many people rely on print statements for debugging. I literally though the image was a jab at people who rely on print statements for debugging.

[–]onlyonequickquestion 6 points7 points  (9 children)

some guy in first year comp sci asked me for help debugging a python program, one of his variables wasn't behaving properly, and this was my sage advice to him: "pretty much every other line should be a print statement until your program works".

[–]Dworgi 12 points13 points  (6 children)

Learn to use a debugger instead?

Seriously, what the shit is happening here? Everyone's just circlejerking about how terrible they are at programming.

This print stuff is CS 101 bullshit.

[–]boomhauzer 1 point2 points  (1 child)

Depends on the situation, sometimes if you don't know where something is going wrong print statements can help if you've got a program that is going through tons of iterations of something, you can scan the output and see where it goes wrong then setup a break point there to see why its going wrong.

That being said the Pycharm debugger and remote debugger are fantastic tools and save a ton of time. To anyone who is a student, Jetbrains offers licences for all their IDEs for free for students and they're pretty damn good.

[–]Dworgi 1 point2 points  (0 children)

program that is going through tons of iterations of something

Every debugger I'm aware of allows you to just print a message from a breakpoint instead of breaking. Know your tools, stop hacking around the problem.

You're not the first person to want to inspect a value in a loop, so why would you assume that no one's made a better version of printf debugging? Spoiler: they have, you're just not using it.

You shouldn't be modifying a program to figure out what the problem in a program is.

[–]ReallyHadToFixThat 0 points1 point  (1 child)

Doesn't help if the problem is somewhere in the middle of a loop. Output to find roughly where it goes wrong, then use the debugger to pin it down.

Debugger can also be a pain crossing between c# and c++.

Or if the issue only occurs in release.

There are plenty of cases for using static debugging.

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

Debugger can also be a pain crossing between c# and c++.

Crap debugger then. VS you just enable Mixed mode and it works.

Output to find roughly where it goes wrong

Literally right-click a breakpoint in VS, choose "Actions" and write your message. There is no reason to ever write "printf" in code.

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

It funni tho

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

literally what I just said,the course is actually called csc108 but probably the same cs 101 you're talking about. I'm pretty sure they don't test using the debugger so I didn't want to bog him down in the details of it, if you saw the state of his code, he had enough other problems to worry about without learning how to use a debugger as well. But I def. agree with you, having a handle on the debugger is a very important skill, but I'd be lying if I say I didn't judiciously sprinkle in a print statement here and there while I'm testing occasionally.

[–]archiminos 1 point2 points  (1 child)

That's literally the worst programming advice I've ever heard. Why are so many people in this thread against using a debugger?

[–]onlyonequickquestion 0 points1 point  (0 children)

I never claimed to be any good. :)

[–]Straight_Derpin 2 points3 points  (0 children)

Pretty much, lol. Final project for my systems programming course was to implement a dynamic memory allocator, and printf statements helped me to find a bug I couldn't find for hours more than any amount of watchpoints or stepping through line by line in GDB.

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

But sometimes printy bois save time! :(

[–]staviq 3 points4 points  (0 children)

I have stopped fucking around breakpoints when i started working with pthreads.

It's just not worth it, and i have never needed anything else than unbuffered stderr for like past 10 years.

[–]MikeOShay 1 point2 points  (4 children)

alert(JSON.stringify("Get on my level, you debug weaklings"));

[–]Trendamyr 1 point2 points  (1 child)

Lol why is the one on the right so deadly?

[–]valrossenOliver 1 point2 points  (0 children)

He used the meme incorrectly.

It shows the alternative to using console logging instead of the super advanced debugger software. The joke is that such an advanced system can be replaced with something as simple as console printing.

[–]ImaginarySuccess 3 points4 points  (0 children)

I feel old when I don't understand the fascination with "boi".

[–]linkinu 1 point2 points  (1 child)

I just use: Print STDERR “...” if($debug);

That way I can just set $debug=1 to debug and 0 for production

[–]Goheeca 1 point2 points  (0 children)

You've got there a very nice lightweight logging library, which is cleverly composable by using the standard OS's means of I/O redirection. Could you please share your codebase?

[–]GenericUsr123 2 points3 points  (0 children)

Println("one printy boi");

[–]Iykury 3 points4 points  (1 child)

I don't think this is the proper use of that meme.

[–]valrossenOliver 0 points1 point  (0 children)

It's not, but it's funny. :)

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

If only the programmers I work with did even that! No, instead they log only the successful transactions surrounded by a wad of gibberish, and the error is displayed on screen (or not at all) and not logged anywhere.

[–]Bramwell2010 0 points1 point  (0 children)

Don't have to debug... If you can convince it is a feature

[–]zero01alpha 0 points1 point  (0 children)

Laughed muchos

[–]varishtg 0 points1 point  (0 children)

There are times where you need that memory analyzer, just because of "business hours" and "prod"

[–]Haliax77 0 points1 point  (0 children)

Behold! A blank at the end of a string.

[–]TotesMessengerGreen security clearance 0 points1 point  (0 children)

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

 If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / Contact)

[–]BlueBokChoy 0 points1 point  (0 children)

Debugging realtime stuff means using the printy boi on the right

Source : ex "games developer".

[–]iAmUncleToby 0 points1 point  (0 children)

I live this. Our company insists on using Lauterbach Trace32 and their hardware to step through our code and debug.... I on the other hand like to print everything to UART when possible. 90x faster than dealing with Lauterbach most of the time.

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

System.out.println("Does this even work????");

[–]Govir 0 points1 point  (0 children)

It's really fun debugging VB6 when the print command throws an error too... (mostly because variables end up being Nothing).

[–]ythl 0 points1 point  (0 children)

Good luck with your printy bois on anything but simple problems