Live data from Hacker News

I am a puts debuggerer

tenderlovemaking.com

41–50 of 60 posts

Re: I am a puts debuggerer

#41

Earlier quoted context omitted.

Just wanted to point out that you may disagree with him here but @tenderlove is far from a novice https://github.com/tenderlove?tab=activity

Yes, it appears I am wrong about my label of "novice" from the pure verbosity point of view. Being a core contributor to anything does not imply being a good programmer. I don't know this person (and don't care, I have no ties to the Rails community). I think that dismissing the use of a runtime debugger is a novice action.

I think being a core contributor to major pieces of software does imply you are a good programmer rather than a novice, whether you know of them or use that software or not. "Pure verbosity" - Really? You want to disparage his contributions? Take it easy, man.

He doesn't "dismiss the use of a runtime debugger", he says "I don’t say this to disparage people that use a Real Debugger. I think Real Debuggers are great, I’ve just never taken the time to learn one well."

Re: I am a puts debuggerer

#42
Since we're all sharing debugging lessons I thought I'd include one for .NET. In System.Runtime.CompilerServices, there are attributes that can be very useful for a logging interface: CallerMemberNameAttribute, CallerLineNumberAttribute, and CallerFilePathAttribute. These add compile-time info to method calls like so:

    void Error(string message, 
    [CallerMemberName] string callingMethod = null, 
    [CallerFilePath] string filePath = null, 
    [CallerLineNumber] int lineNumber = 0);
You then simply call `Error("something wrong with the frobnicator")` and the source line you need to come back to is already there. The only caveat is that this won't work in conjunction with variadic formatting for the message (`params object[]` arguments can't coexist with default arguments). `string.Format` feels like a small price to pay.

Re: I am a puts debuggerer

#43

printf()-based debugging is okay when these statements are temporary, or when they are only present in development branches. At $previousjob we had a guy who literally spent a year adding printf() statements everywhere to production code in order to help himself understand the existing code base he had to work on. "It's not printf()-debugging, I'm doing extensive permanent instrumentation". He even developed a whole…

Oddly enough, I've spent some time working on "white-box" tests that check the log. It takes taste to do well: you have to be careful to log what your program figures out about the domain, rather than just random details. Done right, I find it actually helps refactoring. My unit tests now usually call some top-level function rather than just the sub-component they test. As a result I can make radical changes, like going to client-server or from sync to async, without having to change any tests.

More details: http://akkartik.name/post/tracing-tests

Re: I am a puts debuggerer

#44

I don't even understand the 'have to learn a debugger' statement. Is he referring to things like pry? I rather enjoy the debugger in Rubymine, and part of the reason for this is that it more or less works like every other debugger I have ever used (eclipse, vs, chrome debugger, etc.) There is not much to learn if you have used any debugger in the past.

That which is not learnt is innate. GDB is not innate. Therefore GDB has to be learnt. --- I don't understand your lack of understanding :) EDIT: Addendum: Symbolic debuggers like GDB are non-trivial to pick up, is that what you're arguing against?

Writing to the console is good if you have a console, and don't need to stop the program and examine the state of memory, files, processes immediately before the problem occurs. Otherwise it's a big fail.

Are we supposed to believe that some people can understand unix, c++ etc but cannot learn/keep a cheatsheet handy so they can employ the ~10 commands needed to use gdb fruitfully?

Re: I am a puts debuggerer

#45
post #2

I'm an everything debuggerer. I use print statements when its convenient (mainly when i want to know what's going on in a longer process), i use interactive debuggers when its convenient (mainly when i want to inspect complex data structures), sometimes i run the interactive debugger and then dump a complext data structure to STDOUT with a print (mainly when i want to reference it later on). I don't get the people wh…

The fact remains that when we think of debugging tools we tend to build monolithic debugging environments rather than unix-style primitives that do one thing well. Thinking deeply about when prints work best and how we can ameliorate their drawbacks is a fertile place to change this. A couple of concrete ideas:

a) For a while now, I've experimented with editor macros to comment/uncomment code that insert a special marker after the comment leader (like say //? for C++ or Java) that allows me to programmatically distinguish real comments from commented-out code. An immediate benefit is that I can select large ranges of text and enable/disable prints without messing up interspersed prose. A more subtle benefit is that it lets me leave prints in version control for weeks of time and watch which prints I use most often when debugging. I've also experimented with a couple of subsidiary experiments: a1) highlighting //? comments differently (much less saliently) than real comments, so they don't bother me as much in my editor, a2) having my comment macro set/increment a per-line counter which provides even more fine-grained telemetry about how my codebase is used. It's illuminating to save all the prints you made while debugging a problem that ends up being just a one-line fix. Even if you end up deleting all the prints immediately in the next commit. And if you think it makes merging harder, well that's just a task for another simple unix-like tool: to filter out commented-code before merging, and add it back in afterward.

b) A big problem if you do a lot of printing is to find the right prints that help you debug your problem now. Print too much and it becomes easy to get lost in all the verbiage. I've tried battling this problem with a 'zooming editor' which reads a potentially huge log but displays only stuff at the highest level of abstraction, letting the user selectively click on lines to expand more and more detail around them. I can even bring up this zooming editor automatically when my program dies in debug mode: http://akkartik.github.io/mu/html/090trace_browser.cc.html [1] This is an incredibly useful tool, because it turns a two-sided problem into a one-sided one; instead of having to walk the tightrope between too much logging and too little I can just log everything and poke at it in my leisure.

Not all these ideas are good. I gave up on a2) above after a few months, for example. But there's lots of room for questioning conventional wisdom and trying new things.

[1] Details on my literate format: http://akkartik.name/post/wart-layers

Re: I am a puts debuggerer

#46

This appears to be a post by a novice developer, discouraging the use of time tested, invaluable debugging tools? Encouraging slower, worse debugging...for what? And "tender lovemaking" for the title of a tech blog? That's childish and short sighted. Rails has vibrant problems in its ecosystem (everything is global, tracing behavior is hard, everything is magic, many Rails developers have no idea how what they're usi…

Yes, people who try and inject a little fun into their interactions are just the worst, aren't they? In a professional setting too. It's just shameful behaviour. Also, I'd be really cross if one of my children should stumble across this "tender lovemaker's" blog. I hope this guy is ashamed of himself.

Re: I am a puts debuggerer

#47
post #14

In the embedded world, sometimes you can't even be a puts/printf debuggerer. There have been some situations, typically early in development, where I've had to be a "turn the LED on or turn it off" debuggerer. Amazingly, that binary output is usually enough to fix whatever problem is happening and bootstrap into printf debugging or full ICE interactive debugging.

One time I couldn't get to an LED so I used an IR thermometer pointed at chip to debug it. Telling the difference between hot and cold and whether it was getting warmer or colder told me what I needed to know.

Impressive.

Saying as someone who once debugged something by ear making the motherboard emit a cathode ray tube like hum instead of blinking or beeping.

Re: I am a puts debuggerer

#48
post #38

I guess it is by far easier to be a puts debugger than a printf debugger (I'm saying that as someone who prefers printf over a debugger but pry on Ruby over simple puts). You can get a much longer way with what Ruby lets you do with puts than you would with printf in C/C++. Like the example with `method(:render).source_location` from the article. You can't do that in C/C++ on a general base. Or pretty printing a stru…

__FILE__, __LINE__, __FUNCTION__

Yes, there's no default pretty print for structs, but no sane C programmer would ever expect or want that blubber to come available by default. Mainly because there's very rarely a need to printf-dump anything more than a select variable or a struct field. Different language - different debugging realities.

Re: I am a puts debuggerer

#49
post #2

I'm an everything debuggerer. I use print statements when its convenient (mainly when i want to know what's going on in a longer process), i use interactive debuggers when its convenient (mainly when i want to inspect complex data structures), sometimes i run the interactive debugger and then dump a complext data structure to STDOUT with a print (mainly when i want to reference it later on). I don't get the people wh…

In basic I used the beep() debugger ;)
Post reply on HN