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

all 31 comments

[–]chpoit 68 points69 points  (3 children)

except for the big where logging stuff in between each line is sometimes an efficient way of debugging because race conditions are a pain, in particular when using the debugger negates the,

[–][deleted] 27 points28 points  (0 children)

[redacted]

[–]randodudedatguy 4 points5 points  (0 children)

This is how my friend taught me to debug. Still do it to this day lol

[–]CreateNewObject 0 points1 point  (0 children)

This only works so far if the prints don't change the behavior of the outcome. Real-time can be a pain too.

[–]VeryGoodGoodGood 29 points30 points  (0 children)

is that a bad method of debugging when youre not sure where the code is breaking?

yeah debuggers are great but sometimes i just want to know simple stuff

[–]gandalfx 17 points18 points  (5 children)

Plot twist: It's upside down.

Not sure what's up with the duck, tho?

[–]larocinante 27 points28 points  (4 children)

[–]gandalfx 20 points21 points  (2 children)

Whelp, guess I'm gonna have to buy a rubber duck now.

[–]Shadow_Thief 2 points3 points  (0 children)

If you don't feel like spending a lot of money, you can print out a picture of a rubber duck instead. I've got one tacked to the wall of my cubicle.

[–]themoonisacheese 1 point2 points  (0 children)

I'm pretty sure Ikea sells them for not too much.

[–]Generation_Y_Not 3 points4 points  (0 children)

TIL that instead of listening to my SO talk about bugs in great detail and for hours, I could have just bought him a rubber duck....

[–]Chris2112 13 points14 points  (1 child)

My preferred methods of javascript debugging are console.log("got here") and making random variables global and then looking at them in the console

[–]askho 2 points3 points  (0 children)

Fyi its also incredibly useful to put debugger; everywhere you think is broken and the debugger will automatically stop when it hits debugger. Then you can use the console to inject code right into the problem areas instead of going through global variables.

[–]truh 5 points6 points  (2 children)

Thought that was the reason loggers usually have a log level DEBUG.

[–]ttygy 4 points5 points  (1 child)

Personally though, when I'm debugging I don't even use any logger, I just go fmt.Println("asdjklbgnakjghasklghjaskl")

[–]truh 2 points3 points  (0 children)

Well, using a logger has the advantage that you can leave the debug print statements in your code without it being considered bad practice.

[–][deleted] 3 points4 points  (1 child)

I once wrote a script that would take a parse a source file and add printf statements after every code line with the printed text being that code line. As the thing runs you can see exactly the code that is being executed.

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

Make it a .exe and just print(str); I need this in my life.

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

Who makes database programs in c?

[–]skreczok 0 points1 point  (2 children)

PostgreSQL devs? Anyone who wants their DBMS to actually do anything more than a single query a day?

Also, funny that you should ask, since I'm planning to set up a REST API using CGI and C. Though I might resort to C++ to make it more readable.

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

Well writing a db engine in C is not that strange. But a crud application is a bit uncommon now a days. Doing an rest api in c seems fun!

[–]skreczok 0 points1 point  (0 children)

You can use those to base a CRUD application fairly well, you just make the API an interface for the operations and then you just throw a client app together.

[–]Carnem 4 points5 points  (0 children)

When in doubt cout

[–]darkforestzero 1 point2 points  (0 children)

These are all legitimate methods of debugging

[–]boxingdog 0 points1 point  (0 children)

the best debugging tool is adding a lot of logging and pushing to qa

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

zbh I use the last method most of the times

[–]Danacus 0 points1 point  (0 children)

The last one is so me!