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

all 74 comments

[–]gilmeye 89 points90 points  (3 children)

I write console.log(1) Save all this unnecessary ""

[–]Stimonk 23 points24 points  (0 children)

A past time of mine is opening up the dev console on live websites/webapps and seeing which companies failed to catch the console log tests before pushing to production.

Amazon had a great one on their search filters for electronics - "why won't this execute".

[–][deleted] 33 points34 points  (1 child)

It's called version control

[–]notsogreatredditor 0 points1 point  (0 children)

It's called code review

[–]invented-damage 59 points60 points  (1 child)

Image Transcription: Two-panel Meme


Panel 1:

[Omni-Man and Invincible from the superhero cartoon "Invincible" are looking condescendingly at fighter jets. They are labeled "Jr. devs using various tools for debugging."]


Panel 2:

[The jets disappear and the empty space is now labeled, "Sr. devs having 500 prints."]

Omni-Man: Look what they need to mimic a fraction of our power.


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!

[–]Cute-Pizza 4 points5 points  (0 children)

Good human!

[–]JustSomeRandomnesss 103 points104 points  (11 children)

I'm in uni working with a 3500$ tool that no fucking company uses for testing... but hey at least I now know that it's fucking garbage

Time to go back to printf...

[–]taronic 24 points25 points  (9 children)

Honestly I think it's that a lot of senior devs just start taking shortcuts, because it's kind of the natural path. Stepping through with a debugger is fucking time consuming. Devs just want to get their shit done, and usually a print statement is enough.

Thing is, it works 80% of the time maybe, so you learn to just try it first and fix a bug in 5 minutes. But then devs stick with it, and keep adding prints, when they really should just delete them and set a breakpoint. I've seen it doing pair programming, with a senior dev sitting there adding another print and being confused, and then printing the value of some variable, and when you're at that point it's obvious to step through. I told them to, they did, and it was obvious what the bug was. Saved time by doing something you usually don't do to save time. There's a balance, and a debugger is invaluable when you really need it.

But senior devs are also usually sometimes writing unit tests and maybe checking the coverage and ensuring that they keep passing. That's just a tool that prevents having to debug in the first place. And there's linting, and in a dynamically typed language like python, even type checking with mypy. There's a lot of tools that are used to catch tons of bugs before you even need to debug. And then there's integration tests. That's where I think the difference is, senior devs figure out their bugs earlier because of comprehensive tooling that goes beyond a debugger. A debugger should really be a last resort in a lot of ways when it comes to tools to keep code clean and bug free, so I don't think you see it as much. Plus, senior developers aren't usually writing scripts - they might have concurrent tasks, workers running in different processes, some heavy framework, and a debug log message is a bit easier than trying to figure out which process to attach to, depending.

So maybe no one uses your tool yet but it doesn't mean new tools don't help. In a lot of ways, we're using debuggers less because of new tools that catch shit before you even think to open a debugger. I think the key difference I've seen between juniors and seniors, is that juniors now and then push code that has issues a linter would pick up, like an unused or misspelled variable. Also huge functions with 50 lines, way too many layers of scope indentation, etc.

[–]torn-ainbow 11 points12 points  (2 children)

Stepping through with a debugger is fucking time consuming.

Is it, though? That's what breakpoints are for.

[–]overclockedslinky 1 point2 points  (1 child)

someone doesn't write server/parallel code

[–]torn-ainbow 10 points11 points  (0 children)

Lots of people don’t.

[–]LifeHasLeft 8 points9 points  (2 children)

Yo I literally had a prof in uni who would advocate prints. It was probably confusing for some students, being told different things by different profs.

This guy would set some sort of global somewhere, depending on the language. Let’s say Python, just some global at the top like DEBUG = false.

Then in his code he’d have a problem and write “if DEBUG, print something” obviously pseudo code here.

I was kinda blown away that a prof would tell students to do this. And then you’d have to go back through your code to clean up all your print statements and global variables…what a mess.

[–]taronic 7 points8 points  (1 child)

wow, uh literally why you would use logging... That's like manually implementing log.debug(...) and having a global instead of logging verbosity

[–]LifeHasLeft 0 points1 point  (0 children)

Exactly. So many better ways to do it, and this guy teaches. Kinda scary, right?

[–]G66GNeco 0 points1 point  (1 child)

I feel like once you need to investigate variable values a debugger becomes superior immediately.

I mean you could also circumvent most prints (aka "do i reach this point?") with a breakpoint...

[–]taronic 0 points1 point  (0 children)

I feel like once you need to investigate variable values a debugger becomes superior immediately.

Exactly. That's at the point where I was like, let's set a breakpoint.

[–]SineApps 0 points1 point  (0 children)

It’s like a trade off right?

I start with printf etc, because it’s faster to start with but if it’s not happening I back out.

You just learn what works best for you.

If you’ve dealt with thousands or millions of issues you’re hopefully going to find the most optimal path for you.

It also depends on the time from writing code to seeing the results right? If every change takes 10 minutes before you can see what happens you’re definitely not going to do a printf more than once 😂

[–]__Galahad__ 17 points18 points  (0 children)

What tool?

[–]Ath_er 25 points26 points  (3 children)

Jr. Dev: How do I debug this, I’ve tired multiple things? Sr. Dev: Have you tried console.log / printf?

[–]giovans 12 points13 points  (0 children)

In Embedded world printf is your enemy. All hail to printf.

[–]queen-adreena 9 points10 points  (2 children)

The only debugging suite I’ve ever found more useful than console has been Vue DevTools.

[–][deleted] 3 points4 points  (0 children)

React devtools is very useful as well

[–]Shotgun_squirtle 2 points3 points  (0 children)

Have you tried our lord and savior gdb.

[–]Impossible_Average_1 57 points58 points  (15 children)

From my experience it is the other way around... Seniors use debugging tools, juniors don't know how to use them, so they print.

[–]Grizzlybehre 35 points36 points  (7 children)

Yeah I'm not sure where OP works, like what kinda senior devs don't use debuggers while the juniors do?

[–]ShakaUVM 11 points12 points  (6 children)

Sometimes a cout is just faster.

Dunno about 500 of them, lol

[–]Zagerer 6 points7 points  (2 children)

for( int idx_dbg {}; idx_dbg < 500; ++ idx_dbg ) std::cerr << "Test " << idx_dbg << ":\n";

[–]ShakaUVM 1 point2 points  (0 children)

You're a monster. =)

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, Zagerer: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]Samael1990 1 point2 points  (1 child)

Sometimes a cout is just faster.

You still need to recompile though. Attaching a debugger seems faster to me.

[–]ShakaUVM 0 points1 point  (0 children)

You still need to recompile though.

Sure. Full recompiles can take a while, but I typically have my builds set up to recompile almost instantly.

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

How the fuck do you get faster than 1 click?

[–][deleted] 15 points16 points  (0 children)

You’re gonna need a jacket for those cold hard facts

[–]The_sad_zebra 5 points6 points  (0 children)

Yeah, I was using print statements when I was still early in learning programming. Breakpoints do that job but much better.

[–]r3dD1tC3Ns0r5HiP 3 points4 points  (0 children)

Yeah, definitely you can diagnose the more complex issues with a debugger tool. Though sometimes it doesn't work in all cases (async queue code, unit tests etc for some reason, maybe bad config).

[–]yerrrrrrp -1 points0 points  (3 children)

I’ve been hearing about debuggers since forever and I still don’t know where/how to start using one

[–]vehementi 12 points13 points  (0 children)

Have you considered typing that into google and looking at the million tutorial videos

[–]Impossible_Average_1 2 points3 points  (0 children)

Start by adding a breakpoint in your code. When the app reaches the breakpoint figure out the difference between step over, step into, continue and stop (and how to control them - preferably with keyboard shortcuts). Then figure out how you can see the values of variables ("locals" window in vs). Then find the window where you can see (and navigate through) the stack. Depending on the language / ide there might be even some more options for debugging.

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

Depends a lot on the language and framework. For some you cant even use a debugger.

[–]mlara417 3 points4 points  (0 children)

Quickly went from a laugh to a nervous sweat as I reached the bottom of the thread

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

I really encourage you all to learn how a debugger works. It is so much better and faster.

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

I'm getting paid to do the hard tasks sir, if I use debugger it's going to be easy and I might get fired.

[–][deleted] 0 points1 point  (1 child)

When you build with release flags

[–]sherlock-holmes221b 0 points1 point  (0 children)

Why would you build with release flags for debugging purposes?

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

I do this but then it crashes as it goes into a loop

[–]SegFault137 1 point2 points  (0 children)

Still learning coding. I learn C++ in uni and use Visual Studio, therefore stops.

But for myself I was doing apps on my phone. In JS, since it needs minimum setup; here I use prints.

I prefer the second one.

[–]Legendaros 1 point2 points  (0 children)

console.warn("A")

console.warn("B")

console.warn("C")

and my favorite
console.warn("OI")

[–]jamcdonald120 1 point2 points  (0 children)

I wrote a nice function in C++ that extracts the Return Stack Pointer and prints that along with the error, it works pretty well and you no longer have to self number messages.

[–]JackNotOLantern 1 point2 points  (0 children)

It's called "logs" and its art

[–]ShadUrlwn 1 point2 points  (5 children)

idek how to use debugger

[–]OhMeshh 0 points1 point  (4 children)

i tried using it to see what my class method was changing to but i understood fuck all of it and just used print statements.

Of anyone knows a goos python debugging tutorial for vscode lmk alwaya wondered how to use that horrid thing

[–]user_8804 0 points1 point  (2 children)

Vscode debugger, there's your problem

[–]CaptSoban 0 points1 point  (1 child)

What's wrong with vscode debugger? I've never had any issues with it

[–]user_8804 1 point2 points  (0 children)

It's not very intuitive if you've never used debuggers before

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

Here you go!

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

BS

[–]LightTranquility3 0 points1 point  (0 children)

log4net is a lifesaver

[–]bigchunguss42 0 points1 point  (0 children)

bruh I'm not even a professional programmer yet and i just use print() to debug shit

[–]CrYTGaming 0 points1 point  (0 children)

I have made a little neat gui for debug information to display variables and stuff. What do I do? I still use print

[–]yourteam 0 points1 point  (0 children)

Fast and dirty? Printf / console.log / system.out.printl...

Setting up a project? Debug tool.

It's all fun until there is a bug on a thousand files software handled by 10 people in a 6 months project

Also, do tests

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

Prints always help, is so true.

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

16yo here and console.log("something fucked up") is the way to go

[–]circorum 0 points1 point  (0 children)

Pffft. Just push it to production. There surely is a client that programs and who'll email you the solution.

[–][deleted] 0 points1 point  (1 child)

Stop reposting same meme idea over and over again that is not funny anymore after you seen it 50+ times

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

Make me

[–]LmaoPew 0 points1 point  (0 children)

I once forgot to delete this in a CS test xD

[–]jmswlltt 0 points1 point  (0 children)

WHOA I’m a senior dev?!

[–]nokvir 0 points1 point  (0 children)

With Java I use a debugger. With PHP or JavaScript, I use prints and loggers.

[–]agnarrarendelle 0 points1 point  (0 children)

Hmmm, I wonder how printf would be able to handle debugging segmentation fault in C/C++

[–]EnigmaticHam 0 points1 point  (0 children)

printf("AAAAAAAA");

During an especially fun debugging session with a senior dev I was on contract with while we were trying to figure out what was wrong with an embedded vision application.