https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112016-09-26T18:37:25ZRuby Issue Tracking SystemRuby master - Feature #12790: Better inspect for stdlib classeshttps://redmine.ruby-lang.org/issues/12790?journal_id=606702016-09-26T18:37:25Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>I agree, I'd also love to have a better inspect representation for big decimals and dates.</p> Ruby master - Feature #12790: Better inspect for stdlib classeshttps://redmine.ruby-lang.org/issues/12790?journal_id=606712016-09-27T02:13:42Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Tracker</strong> changed from <i>Misc</i> to <i>Feature</i></li><li><strong>Description</strong> updated (<a title="View differences" href="/journals/60671/diff?detail_id=42541">diff</a>)</li></ul><p>I agree about <code>BigDecimal</code> almost.<br>
<code>Prec</code> may be useful but <code>MaxPrec</code> would be rarely.<br>
And for huge <code>BigDecimal</code>, I prefer <code>_</code> separated representation like <code>Integer</code>.<br>
<a href="https://github.com/ruby/ruby/compare/trunk...nobu:feature/12790-bigdecimal%23inspect" class="external">https://github.com/ruby/ruby/compare/trunk...nobu:feature/12790-bigdecimal%23inspect</a></p>
<p>As for <code>Date</code> and <code>DateTime</code>, do you still need/use them?</p> Ruby master - Feature #12790: Better inspect for stdlib classeshttps://redmine.ruby-lang.org/issues/12790?journal_id=606772016-09-27T08:37:22Zzverok (Victor Shepelev)zverok.offline@gmail.com
<ul></ul><blockquote>
<p>As for Date and DateTime, do you still need/use them?</p>
</blockquote>
<p>Why not? It is a common pattern seen everywhere to use <code>Date</code> when you need, just, err, date (e.g. emphasize the fact that "this variable is granulated to days").</p>
<p>About <code>DateTime</code> matters are, of course, more confusing (as far as I can understand, we had both <code>Time</code> and <code>DateTime</code> initially, because just <code>Time</code> had a limited range, but it became better, so <code>DateTime</code> is, kinda, unnecessary now?..)</p>
<p>Also, I believe I saw somewhere in this tracker statements that <code>date</code> library have no maintainers currently: does it planned to be retired completely?..</p> Ruby master - Feature #12790: Better inspect for stdlib classeshttps://redmine.ruby-lang.org/issues/12790?journal_id=606792016-09-27T09:00:14Zzverok (Victor Shepelev)zverok.offline@gmail.com
<ul></ul><blockquote>
<p><a href="https://github.com/ruby/ruby/compare/trunk...nobu:feature/12790-bigdecimal%23inspect" class="external">https://github.com/ruby/ruby/compare/trunk...nobu:feature/12790-bigdecimal%23inspect</a></p>
</blockquote>
<p>So, you decided to leave scientific notation for any amounts? Could we talk about that?.. It is really hard not to make small mistakes comparing values like <code>0.25E2</code> and <code>0.248E3</code> and so on by eyes, on tests and in console.</p> Ruby master - Feature #12790: Better inspect for stdlib classeshttps://redmine.ruby-lang.org/issues/12790?journal_id=606822016-09-27T09:54:00ZEregon (Benoit Daloze)
<ul></ul><p>Maybe it would be nice to use a formatting like sprintf's %g?<br>
So numbers without a huge exponent would print just like floats.<br>
Actually, following how Float are printed would be consistent (1.234e+57, 12.34, etc),<br>
while keeping the extra info it's a BigDecimal:</p>
<pre><code>#<BigDecimal:1234.5678,#{prec}>
</code></pre> Ruby master - Feature #12790: Better inspect for stdlib classeshttps://redmine.ruby-lang.org/issues/12790?journal_id=607242016-09-30T05:47:45Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>That the object id is displayed also used to confuse me. I adjusted to it<br>
so it is fine but I don't think I ever really needed to know the object<br>
id. Perhaps it visually looks cuter if the object id is shown. :)</p>
<p>On a slightly related note, I think that Aaron Petterson wrote the "I<br>
am a puts debugger" blog entry.</p>
<pre><code>https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html
</code></pre>
<p>I am also a puts debugger, or actually, I am a pp debugger. I usually<br>
end up doing</p>
<pre><code>require 'pp'
</code></pre>
<p>Would be nice if pp would be available all the time without a require<br>
statement. But anyway, sorry for commenting this here on an unrelated<br>
entry, I just wanted to mention it because debug-inspect output was<br>
the topic.</p>
<p>Back to date and time - I actually never noticed this, this is<br>
interesting. But to be honest, I don't think I really needed that<br>
information. I think I have had customized inspect output for my own<br>
code only two or three times in 10 years or so. The only use case I<br>
really once had was for a MUD engine started in ruby, where I needed<br>
the objects (like a sword) to show some more meaningful output in<br>
general. Other than that, I don't think I actually paid that much<br>
attention to the inspect output - providing a to_str (or was it<br>
to_s, I always mix them up) method was then usually more important.</p> Ruby master - Feature #12790: Better inspect for stdlib classeshttps://redmine.ruby-lang.org/issues/12790?journal_id=632332017-02-27T19:16:04Zzverok (Victor Shepelev)zverok.offline@gmail.com
<ul></ul><pre><code>$ rvm use 2.4
$ ruby -rbigdecimal -e "p BigDecimal.new(150)"
0.15e3
</code></pre>
<p>So, the boilerplate dropped yet scientific notation remains? Could I provide patch to get rid of it for "reasonably small" numbers?..</p> Ruby master - Feature #12790: Better inspect for stdlib classeshttps://redmine.ruby-lang.org/issues/12790?journal_id=632342017-02-27T20:36:48Zstomar (Marcus Stollsteimer)
<ul></ul><p>Two thoughts regarding BigDecimal and Float:</p>
<ol>
<li>
<p>INHO it's desirable that the inspect output should be different; it should be possible to distinguish between a BigDecimal and a Float by inspecting it.</p>
</li>
<li>
<p>BigDecimal doesn't use scientific notation in standard form (with a leading digit between 1 and 9), and there are also differences in the formatting of the exponent, see examples below.</p>
</li>
</ol>
<p>Maybe BigDecimal could adopt the style used by Float, with an additional marker/tag(?) to distinguish between them?</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">require</span> <span class="s2">"bigdecimal"</span>
<span class="nb">require</span> <span class="s2">"bigdecimal/util"</span>
<span class="mf">12300000000000000.0</span> <span class="c1"># => 1.23e+16</span>
<span class="s2">"12300000000000000.0"</span><span class="p">.</span><span class="nf">to_d</span> <span class="c1"># => 0.123e17</span>
<span class="mf">0.000000123</span> <span class="c1"># => 1.23e-07</span>
<span class="s2">"0.000000123"</span><span class="p">.</span><span class="nf">to_d</span> <span class="c1"># => 0.123e-6</span>
</code></pre>