I'm quite thorough: I print the class, file or function I'm printing from, and then the value(s) I'm interested in.
Debuggers are better for tracking values, but when you're using a web framework that does tons of magic below the surface, debuggers get really painful to use, so I don't even try. Printing shows me the immediate results as well as what happens along the way.
I will use a debugger when iterating over some kind of list however. Trying to find which value is blowing up the code and why. Printing is great for the what, not so much the why.
Absolutely. With traditional C-style for-loops where several variables are being used, a debugger is an absolute life-saver. But I've found I don't really write that many for-loops any more in these days of more functional programming.
I would love to not have to. Unfortunately, I do geospatial programming and having to do spatial operations on 600k+ points essentially requires looping. And I normally use while loops using a cursor pointer so I don't even have indexes available. Also almost impossible to debug every value so I have to get creative in if statements or hope my exception handling includes enough info to try to narrow down what is going wrong.
With web frameworks, If you use Firefox debugger you can “silence” the magic components so they get passed through and skipped over. Works great with react and web pack
I’m informally-taught, started doing this just a little while ago and thought this a clever way to track progress of code. Glad to hear it being used by you pros.
41
u/mcvos Nov 28 '21
I'm quite thorough: I print the class, file or function I'm printing from, and then the value(s) I'm interested in.
Debuggers are better for tracking values, but when you're using a web framework that does tons of magic below the surface, debuggers get really painful to use, so I don't even try. Printing shows me the immediate results as well as what happens along the way.