Project

General

Profile

Feature #15112

Introdudce the new singleton method STDERR.p

Added by mrkn (Kenta Murata) 11 days ago. Updated 10 days ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:88972]

Description

I sometimes write STDERR.puts obj.inspect to print debug message to standard error.
I want to write it as STDERR.p obj.
It can be realized by introducing p singleton method in STDERR object.

History

#1 [ruby-core:88976] Updated by duerst (Martin Dürst) 11 days ago

#warn writes to STDERR. What about warn_p or something similar?

On 2018/09/13 15:15, muraken@gmail.com wrote:

Issue #15112 has been reported by mrkn (Kenta Murata).


Feature #15112: Introdudce the new singleton method STDERR.p
https://bugs.ruby-lang.org/issues/15112

#2 [ruby-core:88982] Updated by jeremyevans0 (Jeremy Evans) 11 days ago

mrkn (Kenta Murata) wrote:

I sometimes write STDERR.puts obj.inspect to print debug message to standard error.
I want to write it as STDERR.p obj.
It can be realized by introducing p singleton method in STDERR object.

I've heard it is preferable to use $stderr (the current standard error stream) instead of STDERR (the original standard error stream) as warn and similar methods use $stderr. As $stderr can be reassigned, there is no guarantee that $stderr.p would be valid. I suppose you could have STDERR.p write to $stderr, but that may be confusing. It may be more generally useful to add a method to IO that did the equivalent of puts obj.inspect.

#3 [ruby-core:88998] Updated by shevegen (Robert A. Heiler) 10 days ago

I agree with both what Kenta Murata and what Jeremy Evans wrote (to explain,
I have no personal preference; I think both .p() would be useful anyway and
I think this was the spirit of the original suggestion; I love p and pp).

Martin suggested warn_p so I think this addresses more Kenta Murata, but I
think, personally, the net benefit of warn_p may be significantly smaller
than the "puts" versus "p" situation, where I think the gain is quite
significant here, if you write a lot of code that makes use of p for
output. (This is a bit similar to the proposal to do "require 'pp'" by
default, which was a good change IMO).

Anyway, my personal opinion is +1 to the idea behind the proposal - I have
no real preference on it being on STDERR or $stderr or both; I think it may
be useful on its own, no matter where the method ultimately resides.

Also available in: Atom PDF