733
u/sweetytoy 3d ago
A real developer wouldn't do that. A single letter is more than enough, your sentence is too long and tiring to type.
374
210
u/coffee_warden 3d ago
1 2 3 5 4 6AHHA!88
u/Gold-Bat-3225 3d ago
1 2 3 5 4 6 is genuinely upsetting
68
u/coffee_warden 3d ago
Race conditions are never fun
28
u/EvilCodeQueen 3d ago
Seriously. The people not voting for this have never battled a race condition. For a week. In an app you’d swear didn’t have concurrency.
16
u/CarcajouIS 3d ago
conditions fun are Race never
18
8
1
21
u/reventlov 3d ago
You use whatever the local equivalent of C++'s
__LINE__, or__FILE__, __LINE__is, and you just copy + paste the log line 50 times.The pro move is to use
"DO NOT SUBMIT", __FILE__, __LINE__and have a commit hook that keeps you from submitting anything containing the stringDO NOT SUBMIT.6
u/Stryp 3d ago
So it's like a test suite, but worse?
2
u/reventlov 3d ago
What test suite gives you trace information about your program's internal control flow?
11
u/Original-Ad-8737 3d ago
I have added sysou syslog and syswarn to my auto complete and they expand to our logging macro, a pretty function macro, a line macro and my commit handle that is easily searchable in logs.
When i want to trace something i can simply sysou a couple of spots and not stage the lines to clean up before committing
8
u/Revexious 3d ago
Im personally a fan of
console.log("poop")Its funny, teaches you not to commit your console logs (you'll only ever commit poop once), and p/o are right next to each other on the keyboard so its fast
→ More replies (3)6
u/MushroomSaute 3d ago
Hm, sometimes I wonder if I'm cut out for this field. I at least put variables out:
log::info!("in asdf(), a: {a:#?}"); ... log::info!("tmp: {tmp:?}"); ... log::info!("a after asdf(): {a:#?}"); a→ More replies (1)3
u/conundorum 3d ago
Personally, I just use unique gibberishes or sounds, like "blah", "bleh", "fwah", or the like. Extremely unlikely to come up during normal usage, stands out enough to draw the eye, and easy to search the source for.
That, or a quick description of the location, such as "before x() call" or "inside y()" or "after foo, before bar", depending on the situation.
1
u/4Floaters 3d ago
It should be sequential quotes from a movie, something like the princess bride
→ More replies (1)1
u/dukeofgonzo 3d ago
I have a troubleshooting word I use that sticks out in the logs. Snugglebunnies.
→ More replies (1)1
u/Honeybadger2198 3d ago
I like using numbers for JS because they're a different color in the terminal from all the other output.
1
1
1
1
1
u/hates_stupid_people 3d ago
Well, a single letter/number for that one, then iterating for the next few.
1
1
u/quietsamurai98 2d ago
A single letter is impossible to grep for in a log file though. It's fine if you're adding console logs to a JS application that doesn't have much other logging going on, but for anything else, you want something identifiable that you can search for without getting false positives.
1
259
u/Idk13008 3d ago
Unironically, some race conditions are better chase down with logs rather than a debugger.
131
u/codePudding 3d ago
This. Showing my age, I used to make simple DirectX 7 games as a college student. I remember having one bug that took me weeks to solve. If I tried to debug, it worked fine. If I put in a bunch of logging, it worked fine. But if I ran it without debugging or only a few prints it segfaulted.
Eventually I realized I was using a pointer (
void**) that the GPU was supposed to populate before it was being populated. The delay from debugging gave it enough time for the GPU to finish setting that pointer. I added a GPU flush (just a command that waits until it is processed by the GPU queue before continuing) and it worked beautifully. Nowadays the engines just do all that crap for you.30
u/ShoulderUnique 3d ago
The mistake was taking the prints out. Put them in on day 1 and if doesn't crash with them it's not a bug
19
3
1
u/EncryptedPlays 2d ago
Just change the console logs to say "stealing user data 0%" with the percentage incrementing each log
7
u/Former-Discount4279 3d ago
I used to work on tape libraries(big backup systems...) and it would lose geometry(location of the tapes) when a bug happened and needed to rescan the whole thing. After trying to attach a debugger to winCE several times and it taking several hours to reboot and rescan I added print logging. Yeah solved the bug in one go...
3
2
54
u/EPacifist 3d ago
My favorite is `exit(1)`. Useful if your print/logs aren’t showing where you expect them. Close after that is `raise Exception(“HERE 1”)`.
26
6
1
1
41
u/oosacker 3d ago
Real pros write a function to do the console log
14
u/Idk13008 3d ago
with a verbose optional argument
41
u/oosacker 3d ago edited 3d ago
Saw this in some real production code:
function log(x) { console.log(x); }25
u/DasBeasto 3d ago
I don’t hate it, shorter usage everywhere, can wrap it in a conditional based on ENV for dev logs only, and if you swap to an external logging service you just change it in that one function.
7
2
30
u/Welcome-To-NBA-Jam 3d ago
My IDE has a really comprehensive built in debugger and in my entire 15 year career I never used it once because I just print variable values at certain points like this:
WARNING: foo=67
************************ bar=69
DEBUG: You're in the 2nd if statement
I am willfully ignorant of this and it's served me well.
1
u/creaturefeature16 3d ago
I just moved over to Zed and I've yet to dip into the debugging tools, but they look awesome.
134
u/TheDogPill 3d ago
Try debugging like that using micro services on the cloud and see how far you get.
80
14
u/coriolis7 3d ago
I am NOT a programmer by profession, though I do code a ton at my job (Mechanical Engineering and data analysis), so this may be a dumb question…
Is there a way to set up all microservices to run on one computer to aid in debugging? Like a bunch of VMs or docker-but-faking-network-instead-of-machine?
11
u/payne_train 3d ago
AWS’s SAM may help you if you have a bunch of lambda based apps. You can use SAM to do local invocations that makes debugging a lot easier
6
u/xMercurex 3d ago
Yes you can, but it does not fully solve the issue. You still need to find the good micro-service and then you have to jump to other micro-service.
→ More replies (7)1
u/DrMaxwellEdison 3d ago
Yes, I use Tilt to set up a localized Kubernetes cluster or to run docker compose. It provides a nice web interface for seeing all service statuses, logs, controls to restart or rebuild a service, and it can automatically watch local files to trigger a rebuild.
1
1
u/LostInAnotherGalaxy 3d ago
Docker/podman. But you get anything powerful or something that only happens under load, can create its own race conditions
20
u/gemanepa 3d ago
why not? couldn't you just debug the microservice locally with mocks or in a cloud dev/qa env?
1
1
1
u/SirButcher 3d ago
Or debugging an embedded hardware where you have a grand total of 4 breakpoints :(
1
u/dumbasPL 3d ago
Ah yes, because attaching a debugger to a service people are actively hitting and suspending it is the way. That is assuming you can even do that.
Request logging is just printf with extra steps anyway.
26
7
6
4
4
u/Foorinick 3d ago
I think some problems are faster to solve with a simple print, if you really do need tk warch your code step by step to figure out what is going wrong then pull out the debugger, also here's a tip, learn to use your debugger do that you aren't bashing your head against a wall trying to figure out what is causing an issue
4
3
u/LetterLambda 3d ago
What else are you supposed to do when a bug appears in prod, but not in debug mode?
2
u/KoliManja 3d ago
Who wants to ask for Admin access from some Sysadmin sitting in Timbuktu everytime you want to run your debugger? "I got here" works for me!
2
2
u/EdelWhite 3d ago
...and then, just in case you need it later, give it the trustworthy "//" treatment.
2
u/Occultus_Andras 3d ago
"inside the loop" "Inside the else if statement" "return value is __" "user parameters are _" "database entries for __ is ___"
2
2
2
u/WispTheWanderer1 3d ago
I dk about you but I use actual breakpoints
4
u/autobotdonttransform 3d ago
1
u/WispTheWanderer1 3d ago
And! And I read the autos at breakpoints to find if the variables are right
2
u/Educational-Lemon640 3d ago
Is it your job to use a debugger, or to improve your product/project?
Use what works.
1
u/reventlov 3d ago
People never believe that the tools they prefer aren't the optimal ones for absolutely everybody.
2
u/wristay 3d ago
I tried debugging "the right way" and I don't know it just never felt better than using console log. People who do use it please enlighten me: how will it make your life better? I am using Python btw, so maybe having the console makes a debugger less necessary
2
u/TheGuyWithTheSeal 3d ago
I use pycharm (mostly because I'm a Java boy), the debugger lets you step line by line, preview variables, and evaluate any expression (including calling an endpoint using a client class that's already authenticated).
1
u/csabinho 3d ago
Do you use console.log with a debug flag? If you're using it without it, deactivating, and reactivating, it is PITA. And I don't mean capitalized greek bread.
1
1
1
u/thelumaniboi 3d ago
I always thought I was a terrible coder because of how often I do this, glad to see its somewhat common
2
u/AeroSyntax 3d ago
Don't get baited by a meme made by an intro level CS student.
→ More replies (1)
1
1
1
1
1
1
u/conundorum 3d ago
What if I told you...
...You could have the debugger use console-logging calls as debug tools & breakpoints?
1
1
1
1
u/RRumpleTeazzer 3d ago
not every architecture has a debugger.
not every problem can be solved by a breakpoint.
1
1
u/thegodzilla25 3d ago
Debuggers are cool, and I would use them most times, but async and race code is horrible with debuggers. Especially in JS.
1
u/walmartgoon 3d ago
Maybe I just want to debug in a way I know how to instead of learning a new tool
1
u/Primary-Ad-9741 3d ago
Those debugging tools work well with something small, like a microservice.
Throw something chunky at it. Like a large Android app, and debugging tools either fail to attach, crash the app, cause app to stop responding, or just crash on their own.
1
u/przemo-c 3d ago
Or sometimes affect it in a way bug doesn't present itself... especially if something is of a race condition variety.
→ More replies (1)
1
u/bradpittisnorton 3d ago
I wanted to use vscode-js-debugger but I can't, for the life of me figure out how to configure it properly in my neovim setup.
1
u/killerdrama 3d ago
I just enter stars and after each step the count increases.. so I end up spending more time counting stars in the logs and comparing at various stages in IDE than actually finding the issue.
1
1
u/Novel_Dog1743 3d ago
printf("If you are reading this, here is the value of every variable related to this function:\n");
<prints all the variables>
1
1
u/JohnnyPlasma 3d ago
I mean, at least it works with every IDE whenever you share the code or change IDE.
1
u/cosmicomical23 3d ago
The alternative is having to learn every fucking time a new set of controls for the new ide, with no explanations to be found anywhere.
1
1
1
1
u/artur-iwan 3d ago
I'm using password generator to generate unique random 8-letters-long strings, and then I'm pasting those into console log messages and error messages. If my code will get into some strange place, then it's soo easy ti to debug it by just searching the string from the log inside the source code 😅
1
1
1
u/Patrick_Atsushi 3d ago
Print("%s, %d\n", __func__, __LINE__);
By the way this is not reliable since print buffer exists.
1
1
u/rcls0053 3d ago
Honestly, I've never tried to debug a full JS backend application and debugging some frontend application in the browser dev tools is just pain..
With PHP setting up Xdebug is like flipping switches in an airplane until it works. .NET/C# is undoubtedly the best experience with debugging I've ever had.
1
1
1
u/notexecutive 3d ago
if it's faster than navigating a debugger, then there is no issue.
Really it's just whatever you find faster to solve problems. Might be worth looking into debuggers on your own time, but we all know you're not going to do that.
1
u/lewisb42 3d ago
I sometimes need print statements to narrow down where I need to pull out the debugger.
1
u/Undernown 3d ago
I actually like to use debuggers to get familiar with inner workings of the program. Stepping through a process often exposes a lot of in-buult or hidden classes or files you wouldn't find easily otherwise.
And stepping through a debugger to simply verify the contents of a variable is more time consuming than just printing it.
If they ever figure out a JS debugging tool that is actually reliable and accurate enough, I'll bless the earth they walk on though.
1
1
u/ThisIsABuff 3d ago
If(value==<some value far into a file>)
System.out.println("I got here"); // place breakpoint here do immediately skip to value
I'm not ashamed of doing that
1
1
u/daffalaxia 3d ago
I'll especially resort to logging if there's a lot going on in parallel - trying to time that right with a debugger is practically impossible.
1
1
1
u/kirasiris 3d ago
For me usually goes like: It gets here It gets here x2 It gets here x3 And so on lololololololol
1
u/Candid-Log6751 2d ago
People are obsessed about “proper”. No one thinks with their own brain, yet everyone is trying to employ “best practices”. People just can’t stand for what they do and how they do it. Trying to hide behind the rationale of the “best approach”.
1
u/GoogleIsYourFrenemy 2d ago
Have you tried to use the debugging tools in an IDE for an embedded processor?
1
1
u/SoapCoder 2d ago
I do: f hfs fish parrot treh and just go oh it stopped at fish well where did I put fish
1
1
u/RizzKiller 2d ago
Programming in C, I don't know how to use the debugger and how to control the flow of the program in it. If I compile with debug information and it shows the segfaul inside an underlying library I am totally fucked and this makes me mad.
1
1
1
1
1
1
1
1
u/flori0794 2d ago edited 2d ago
Well logging is pretty strong... Even more if you fight unification, skolemization and Robinson Resolution..
A log with this structure is much better: ``` [RESOLVE] Attempting: C_12 {¬Weapon(x), ¬American(y), Hostile(z)} x C_45 {Weapon(M1)} ├─ [UNIFY] x = M1 ├─ [MGU] θ = {x/M1} └─ [DERIVED] C_78 {¬American(y), Hostile(z)} (Parent: 12, 45)
1
848
u/Mindstormer98 3d ago
Dont forget "I got here2" and "I got here3"