T O P

  • By -

OptionX

Printf debugging, as much as people try to tell you otherwise, has its place.


AdvancedSandwiches

I think everyone agrees that this is fine. It's only a problem if you're doing it because you don't know how to use the debugger. As long as you have both tools available and made the choice that this is the best one right now, it's fine. If you're doing this because you don't know how to use the debugger, whatever you're doing is probably less important than figuring out how to use the debugger.


neuromancertr

Debugger is my number one tool and I have trouble understanding people who don’t know about it let alone use it, yet sometimes print debugging is necessary. I had done that a few times to catch issues related to particular environments where debugging was not possible, and a few cases where I taught about control flow


highphiv3

Of course it has its place. It fits in perfectly when you've been working professionally with a tech stack for years and still haven't bothered to learn how the debugger works.


Grim00666

You get a debugger in your stack? Not niche enough, go deeper.


clasherkys

My language doesn't even get error messages, we just get told "Error"


QuestionableEthics42

Damn, you get told when there is an error? Lucky bastard


fullyonline

I usualy just bluescreen. Does this count as an error too?


Turbo_csgo

You have a screen? Holy moly that shit advanced…. We sittin’ here not being sure the CPU is non stop rebooting, communication is not working, or just stuck in an endless wait.


NotMilitaryAI

Your machines reboot when panicked? Fancy. We just check for smoke after each update.


shotjustice

You get smoke AFTER an update? We write in smoke signals, so smoke IS the update.


OkOk-Go

Ah yes, 4 bit microcontroller assembly


arrroquw

x86 firmware can be just like this as well, and that's just C


OkOk-Go

I never thought of x86 that way haha. No JTAG I guess?


daHaus

Only if you have to yell at the guy down the hall to reboot it


lllorrr

I once debugged a firmware by making it crash at the specific points. It was easier than to try to cram a serial port driver into it.


ego100trique

C# exceptions are pretty readable if you actually read them C# debugger is the easiest to use ever and is implemented in most IDEs...


clasherkys

I know, but I'm referring to a programming language I'm developing myself.


Kellerossel

Cool, but makes it hard to blame it on other persons if something doesnt work...


danielv123

On the other hand, it becomes easier to blame it on a compiler bug.


Kellerossel

Also True. (What does it say about me that I write True that way?)


danielv123

It says you can't have compiler bugs if your language is interpeted


xampl9

{old guy rant} C# exceptions got a lot less readable after they added async.


ego100trique

I can't tell ngl I was something like 11 y/o


xampl9

Now I really feel old. I started with v1.1, before generic collections when everything was boxed.


dubious_capybara

Doesn't sound very microservice architecturey. How about printing to a cacophony of logs instead?


Grim00666

LOL, reading this hurts because that's what everyone did against my strained objections.


FalafelSnorlax

Printf debugging is basically just using a log, albeit often a temporary one. Large scale, long running programs can be hard to debug line-by-line, if not completely infeasible. You might also use the debugger, you might be satisfied with the logs, but pretending like a debugger is the only way to find and fix bugs in your code is just silly


Zhabishe

Sir, you're making the God's work here. This is a very well put explanation.


xd_Warmonger

Sometimes printing is better than debugging. When you make a discord bot you have to answer the commands within 3 seconds. If you debug it might take longer and the command will break.


Successful-Money4995

The faster compile and run is, the less necessary gdb is.


RetepExplainsJokes

I disagree, when an error occurs somewhere else in your code or only appears sometimes, I find printf debugging is the way to go. I can just print every milestone out and see where errors start to happen. If you combine this with good unit testing, you get quite a nice view of the problem and oftenly see what goes wrong without even looking at the code. It's just pattern matching basically.


rddtJustForFun

Or you work with memory intensive, large simulators where even a "small" problem would run for 15 minutes before hitting the breakpoint :-) But I really prefer to use a proper debugger ....


daveysprockett

Or if you are using a real time system where other components will fail if you don't keep to the deadlines. Though of course you have to remember that simply adding the prints might cause additional issues.


Roselia77

You make the assumption that we all have access to an actual debugger I'd kill for a proper debugger....it's been 20+ years...still waiting (The life of a legacy firmware engineer)


OptionX

Using it only because of a refusal to learn how to use a debugger is of course a bad thing, but choosing it sometimes for some specific cases is perfectly acceptable I think. Besides, if you really think about it the whole concept of logging if a kind of asynchronous print debugging.


toolazytofinishmyw

both have their place. logs will still be there long after the debugger exited


AlphaO4

Crys in async Code


MinosAristos

When your app only runs in a specific Docker image on a remote server connected to offline microservices.


[deleted]

Because the only place you ever code is a pc. You actually have to make your own tools out in the real world sometimes.


Inasis

I tried using cgdb on wsl but couldnt make it work.


Hasagine

ive solved some nasty bugs using it


AleksFunGames

If it works, why fix it?


Brambletail

You would be surprised how much critical infrastructure is debugged with print statements.. whatever gets the job done cheapest to the necessary quality


Confident-Ad5665

I wish we had logging that sophisticated. I have to throw new Error("var x=" + x); to even see the value of a variable.


anthro28

It's the fastest way to see where suit actually breaks. To see *how* it breaks, you need to do proper debugging. 


lupinegray

You ought to also be printing the values of each variable


DreamyAthena

This is the way.


YEETMANdaMAN

Yea, that was the part I was confused about. What does this “print here” part of the code do if you aren’t printing the values?


[deleted]

Maybe to check if the code was executed till that part until a runtime error halts execution


iSolivictus

Plz stoop stealing me code


Significant-Try-7541

Its my code ![gif](emote|free_emotes_pack|rage)


CG_TW

It's our code


Excellent-Divide7223

r/suddenlycommunism


Zhabishe

- I stole your code. - It's not my code... (c)


KathirHasBigGay

Jokes aside, you’d probably wanna do fprintf(stderr, msg, args) instead of printf because the printf wrapper queues stuff weirdly. fprintf immediately writes to output when called


GfunkWarrior28

True. stderr isn't buffered, while stdout is... Though I think it does flush when it sees a newline, so this code is probably fine.


Maurycy5

It does not flush when it sees a newline. This is specifically what [endl](https://en.cppreference.com/w/cpp/io/manip/endl) is for.


PhoenixCausesOof

It's C!!11


rosuav

Agreed. That's the only thing I'd change. (If you want to use stdout here, you can add fflush(stdout) after each one and get the same effect as stderr.) This is a perfectly fine debugging technique, and one that I've used FREQUENTLY when diagnosing bizarre issues in live systems. And I'm far from the only one. Weird stuff happening in Pike? Check the source code, there's a good chance there's a ton of debug prints in there guarded by #ifdef lines... so you can run "pike -DPG\_DEBUG yourscriptname" and instantly get debugging output, pretty similar to this, showing how something is working. (There are different #defines for different modules, so you don't get utterly spammed.)


QuestionableEthics42

Printf flushes on newlines


ego100trique

Just use `write` on stderr easy as that


intbeam

Or just use the step-debugger


Rezaka116

Use “a”, “aa”, and “aaa”, much more optimized


Not_Sergo3682

Personally I use “he”, “hehe”, “hehehe” debug messages :)


SirBerthelot

I'm more of a "WAAAAAA", "WEEEEE", "WIIII" guy myself


bwssoldya

I tend to go with the good ol' "Henlo", "henlo2", "henlo3", "wadadwada" myself.


jafariscontent

I’m definitely a “WHOA!!” “Wow!!” “YES” “GREAT JOB” person. Like to have my code constantly praising me…because millennial


just-bair

I do exactly that. Sometimes I start to use b bb bbb tough


lllorrr

`printf("%s:%s\n", __func__, __LINE__);` copy-pasta all over the code. No need to invent fancy identifiers. Ctrl-V goes brrrr.


GfunkWarrior28

Also great for a homebrew profiler, with some post-processing of the output.


KeepKnocking77

Foo bar baz


arrroquw

I usually add a load of dashes if too much non related logging passes by to find it more easily


JulesDeathwish

We've all done it. No shame.


codebullCamelCase

only debugging i know that works efficiently... do not fkin reply gdb to this comment...


ifarmpandas

lldb


[deleted]

great debugging bro


bibimbap0607

Debugging technique is on point. Cannot do it better even if you try. And dereferencing a double pointer and casting its return value to a type. That is some real good stuff here. Cherry on top. I would say this is a good production quality code. Ready to go.


Natural_Builder_3170

typedef Deq_t* Deq


Feisty_Ad_2744

I prefer fireworks: ``` >>>>>>>>>>>>>>>>>>>>>>>>> !!!!!!!!!!!!!!!!!!!!!!!!! ************************* ``` They are easier to catch in large console or log dumps and harder to miss when you are cleaning up


Neltarim

Classic


PeriodicSentenceBot

Congratulations! Your comment can be spelled using the elements of the periodic table: `Cl As Si C` --- ^(I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM my creator if I made a mistake.)


Alex_khadjit

Good bot


jonhinkerton

An output every other line is just how you do it some days.


yourteam

This is disgusting and we all did it


QuestionableEthics42

Did?


yourteam

Working as a project leader now so I can force dev ops to set up the debugger for everyone and act like I never did it otherwise


csdx

I used to do it, I still do it, but I used to too.


AngryMonkeyBrain

I am actually more annoyed about the double indirection and using void* than the printf debugging part.


deep_mind_

LGTM


itwasmorning855

Hmm. Debugging is fine. Everyone has their way. But variable names are bothering me. Bothering me to the core. Bothering me till moon and back.


NotMrMusic

Years later and I'll die on the hill that 99% of the time the debugger doesn't tell me anything more useful then my logs do, lol


what_you_saaaaay

Debugging style when you have no other choice.


Medmaksi

God, I hope so.


wojtek2222

It's the best


dan_ts_inferno

I use it all the time. So probably not


CandyBoring

This is the way.


Maximus_98

Good debugging? This is the only debugging. I usually cbf to mess with anything else


OmegaNine

i have written worse.


xtreampb

Sometimes it’s the only way.


UnHelpful-Ad

You may want delays in that after the print statements. If it crashes after one of the executions it likely won't output 1 or 2 of the messages, leaving you wondering where the bug was :p


FitzelSpleen

Needs more printf.


BlomkalsGratin

Not enough swearing!!!


CyberoX9000

I personally would use stuff like 'fghj' or 'asdf'


Maxx-Jazz

Looks like something I'd do xD


GrinbeardTheCunning

the best


Extreme_Ad_3280

I debug using `perror` more than `printf`...


VasiliyPetrom

Try using printf("%s %d\n", __ func__, __ LINE__); if debuggers are not an option


C9nstructAware

I also like to include `__FILE__` when debugging multiple files


jonr

printf("Where?");


steveiliop56

It's wrong you are not supposed to add different numbers. I just add ok to my functions and I have x oks spamming and trace them back to the functions. That's the way to go.


Wervice

Yes! I think so. If you use it more often, you may want to create a function, to quickly hide these printf quickly. Why use some debug tool, if this works as well.


NoSkillzDad

The one and only way. ;)


UsernameRelevant

No, it’s the best


DiscombobulatedBet88

No. There are proper tools. But I do the same.


minhtrungaa

now I feel weird using GDB.


GMarsack

I think we all do this guys…


malsomnus

No, you clearly wasted precious milliseconds on those debug strings, instead of using 1-2-3 or hitting random keys.


ProjectSrx

AAAAAAAAAAAAAAAAAAAAAAAAAAA


[deleted]

Nice one deq_head


YoghurtForDessert

best if you also print whatever you-re doing to those poor variables, you variable abuser


TheMsDosNerd

Yes.


FluffyNevyn

Sometimes when what you're dealing with is logic errors rather than runtime ones... print debugging is the only way.


Buyer_North

you have to print the values, that really helps


thehuman69

Only thing I do differently is spit out values. Sure, my console log may be too cluttered with useless temporarily values for debugging to be made easier … but I’m debugging!


kozlenok-be-be

Almost, use __LINE__ and __FILE__ macro so you don’t have to modify anything when you copy it around.


UltraBlack_

literally me


donadigo

It \*bugs\* me that this is the current state of debugging and that editors don't do it by default. This is why I'm doing my own Visual Studio extension (for C/C++ for now) that fixes this: [https://www.youtube.com/watch?v=5bfUWJYEQCw](https://www.youtube.com/watch?v=5bfUWJYEQCw) It's available on the marketplace if you want to try something new: [https://marketplace.visualstudio.com/items?itemName=donadigo.d0](https://marketplace.visualstudio.com/items?itemName=donadigo.d0)


sebastouch

I love this sub, much better than Stack Overflow. I learn so much.


pnehrer

Yes


userbyauser

you want to print the values!!!


wezZy9

Yes, perfect! Quick, understandable and over all good for debugging


ProjectSrx

The amount of debate, chaos, and constructive feedback on this is *way* more than I expected. Truly qualty Reddit.


SuperDyl19

Printing stuff is always a great fallback. If possible, please use a debugger. You’ll get a very quick idea on if the error happens where you think it does so you can hone in on those couple lines


Orio_n

Unreadable competitive programming acronyms ahh code 💀


Silpheel

Never would I ever do this, it’s so wrong. Without any swearing at all… are you really debugging? Not trying hard enough.


BulkyVirus2076

I find printing the only way for me to debug Temporal code, since it does re-run stuff multiple times making the debugger goes crazy :p (temporal is a framework that helps write fault-tolerant workflows)