$stderr debugging library

I’ve got a library I use for writing temporary debug output to $stderr.
Why $stderr? Because I work with command-line programs that employ a
lot of stdout redirection; I want the debug output to be visible on the
console rather than redirected along with the program’s $stdout.

Q: What’s the prior art? Does some gem already do any of what this
library does?
Q: It this generally useful? That is, does anyone else debug by writing
to the console?
Q: What would be a good name for it, if published as a gem?

Features include:

  • Writes to $stderr instead of $stdout
  • Can automatically print filename and line number
  • Can automatically label the values being output
  • Can easily inspect the middle of a call chain

Details:

Kernel#q is like Kernel#p, except that it writes to $stderr.

Kernel#qq is like Kernel#pp from the ‘pp’ library, except that it writes
to $stderr.

Kernel#ql is like Kernel#q, but it also outputs the file/line from which
it was called:

 ql "foo"    # writes: test.rb:8: "foo"
  • Output can be automatically labeled:

    foo = 1
    bar = 2
    q {‘foo + bar’} # writes: foo + bar = 3
    ql {:bar} # writes: foo.rb:9: bar = 2

Kernel#tapq makes it easy to examine the middle of a call chain:

 ['1', '2'].map(&:to_i).tapq.map(&:even?)    # writes: [1, 2]

Best Regards,
Wayne C.

On Aug 28, 2014, at 11:29 AM, Wayne C. [email protected] wrote:

Q: What would be a good name for it, if published as a gem?

Obviously: q

See also “d” and “g”

On 08/28/2014 08:43 AM, Alex C. wrote:

wrong/README.markdown at master · alexch/wrong · GitHub

GitHub - jugyo/g: The Kernel.g that works like Kernel.p by using terminal-notifier or growl.

Very helpful, thanks! The way the “wrong” gem’s #d method is parsing
the source is superior to my cheesy eval-the-string approach. I will be
borrowing from that gem.

Unfortunately, there is already a “q” gem. For now, I’m using the name
“print_debug.” It’s not a great name. It just stinks less than the
other names I’ve come up with.

Regards,
Wayne C.

Sounds like a useful gem.

On 14-08-29, 6:55, Wayne C. wrote:

Unfortunately, there is already a “q” gem. For now, I’m using the name
“print_debug.” It’s not a great name. It just stinks less than the
other names I’ve come up with.

How about “cute_print”: synonymous with “pretty”, and sounds like “q”.

Andrew V.

how about $stddebug?

Adam, Andrew, and Alex (the A team!), thank you for your help. I liked
Andrew’s suggestion best:

 http://rubygems.org/gems/cute_print

Regards,
Wayne C.