https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112020-11-20T07:21:47ZRuby Issue Tracking SystemRuby master - Feature #17336: using refined: do ... endhttps://redmine.ruby-lang.org/issues/17336?journal_id=886192020-11-20T07:21:47Zk0kubun (Takashi Kokubun)takashikkbn@gmail.com
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/88619/diff?detail_id=58333">diff</a>)</li></ul> Ruby master - Feature #17336: using refined: do ... endhttps://redmine.ruby-lang.org/issues/17336?journal_id=886202020-11-20T07:22:26Zk0kubun (Takashi Kokubun)takashikkbn@gmail.com
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/88620/diff?detail_id=58334">diff</a>)</li></ul> Ruby master - Feature #17336: using refined: do ... endhttps://redmine.ruby-lang.org/issues/17336?journal_id=886212020-11-20T07:23:08Zk0kubun (Takashi Kokubun)takashikkbn@gmail.com
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/88621/diff?detail_id=58335">diff</a>)</li></ul> Ruby master - Feature #17336: using refined: do ... endhttps://redmine.ruby-lang.org/issues/17336?journal_id=886222020-11-20T07:24:26Zk0kubun (Takashi Kokubun)takashikkbn@gmail.com
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/88622/diff?detail_id=58336">diff</a>)</li></ul> Ruby master - Feature #17336: using refined: do ... endhttps://redmine.ruby-lang.org/issues/17336?journal_id=886362020-11-20T10:39:35Zzverok (Victor Shepelev)zverok.offline@gmail.com
<ul></ul><p>Why not <a class="issue tracker-2 status-1 priority-4 priority-default" title="Feature: Shorter syntax for anonymous refinements (Open)" href="https://redmine.ruby-lang.org/issues/16241">#16241</a>?.. <code>using refined: Array do</code> seems redundant to me, as both significant words (<code>using</code> and <code>refined</code>) are related to the same fact: "We are dealing with refinement here".</p> Ruby master - Feature #17336: using refined: do ... endhttps://redmine.ruby-lang.org/issues/17336?journal_id=886382020-11-20T12:40:00ZEregon (Benoit Daloze)
<ul></ul><p>How about:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">class</span> <span class="nc">Foo</span>
<span class="n">using</span> <span class="k">do</span>
<span class="n">refine</span> <span class="no">Array</span> <span class="k">do</span>
<span class="k">def</span> <span class="nf">flat_map!</span><span class="p">(</span><span class="o">&</span><span class="n">block</span><span class="p">)</span>
<span class="n">replace</span><span class="p">(</span><span class="n">flat_map</span><span class="p">(</span><span class="o">&</span><span class="n">block</span><span class="p">))</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="n">refine</span> <span class="no">String</span> <span class="k">do</span>
<span class="o">...</span>
<span class="k">end</span>
<span class="k">end</span>
</code></pre>
<p>So let <code>using</code> take a block instead of a positional argument.</p>
<p>That way, it's also possible to refine multiple classes/modules at once, which is often better than multiple <code>using</code> calls (notably, such methods can use the refinements of each other and it's more concise)</p> Ruby master - Feature #17336: using refined: do ... endhttps://redmine.ruby-lang.org/issues/17336?journal_id=886482020-11-20T17:00:13Zk0kubun (Takashi Kokubun)takashikkbn@gmail.com
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><blockquote>
<p>Why not <a class="issue tracker-2 status-1 priority-4 priority-default" title="Feature: Shorter syntax for anonymous refinements (Open)" href="https://redmine.ruby-lang.org/issues/16241">#16241</a>?</p>
</blockquote>
<p>Works for me :) Honestly <code>whatever Array do ... end</code> sounds fine. When I tried to implement a quick version, I picked <code>using Array do .. end</code>, and it was changed to this proposal because some others said it should be keeping the word "refine". I also thought, "well, it's also using in place", but it's not a big deal. If <code>refining</code> is there, I'd be happy to use it. Plus, the ticket mentions <code>using_refined</code> too. I'm closing this as a duplicate.</p>
<blockquote>
<p>How about:<br>
So let using take a block instead of a positional argument.</p>
</blockquote>
<p>It might be helpful anyway, but a part of the ticket's motivation was to eliminate the deep indentation.</p> Ruby master - Feature #17336: using refined: do ... endhttps://redmine.ruby-lang.org/issues/17336?journal_id=886492020-11-20T17:00:58Zk0kubun (Takashi Kokubun)takashikkbn@gmail.com
<ul><li><strong>Is duplicate of</strong> <i><a class="issue tracker-2 status-1 priority-4 priority-default" href="/issues/16241">Feature #16241</a>: Shorter syntax for anonymous refinements</i> added</li></ul> Ruby master - Feature #17336: using refined: do ... endhttps://redmine.ruby-lang.org/issues/17336?journal_id=886562020-11-20T19:13:32ZEregon (Benoit Daloze)
<ul></ul><p>k0kubun (Takashi Kokubun) wrote in <a href="#note-7">#note-7</a>:</p>
<blockquote>
<p>It might be helpful anyway, but a part of the ticket's motivation was to eliminate the deep indentation.</p>
</blockquote>
<p>Is it annoying in practice?<br>
It kind of seems nice to have the outer <code>using do ... end</code> which is saying "below are local monkey patches for this file".<br>
Instead of having to check if there are further <code>using refined: Array/refining</code> calls one after another.</p>
<p>And if those refinements are not trivial and the implementation needs quite some indentation, maybe the refinements should be defined in their own file under some module, that also solves the indentation.</p>
<p>I guess an example of real code where the deep indentation is problematic might help to convince me and maybe others.</p> Ruby master - Feature #17336: using refined: do ... endhttps://redmine.ruby-lang.org/issues/17336?journal_id=886632020-11-21T03:51:23Zk0kubun (Takashi Kokubun)takashikkbn@gmail.com
<ul></ul><blockquote>
<p>Is it annoying in practice?</p>
</blockquote>
<p>In practice? Nah, maybe not for many people, at least you. I admit I'm a bit extreme about indentation, and for sure it annoys <em>me</em>.</p>
<blockquote>
<p>It kind of seems nice to have the outer using do ... end which is saying "below are local monkey patches for this file".</p>
</blockquote>
<p>For me, a word <code>refine</code> is enough to expect a monkey patch.</p>
<blockquote>
<p>I guess an example of real code where the deep indentation is problematic might help to convince me and maybe others.</p>
</blockquote>
<p>While I would say it's not a problem for many people but me, here's the deepest indentation of <code>def</code> I've ever seen: <a href="https://github.com/rails/rails/blob/v6.0.3.4/activejob/lib/active_job/arguments.rb#L73-L96" class="external">https://github.com/rails/rails/blob/v6.0.3.4/activejob/lib/active_job/arguments.rb#L73-L96</a></p> Ruby master - Feature #17336: using refined: do ... endhttps://redmine.ruby-lang.org/issues/17336?journal_id=886772020-11-21T14:41:25Zzverok (Victor Shepelev)zverok.offline@gmail.com
<ul></ul><blockquote>
<p>It kind of seems nice to have the outer <code>using do ... end</code> which is saying "below are local monkey patches for this file".</p>
</blockquote>
<p>I'd say that one of the important usage of refinements (as for me) is <em>small</em> adjustments to core/third-party classes, that make sense in the current context. And the whole point of this ticket, as well as <a class="issue tracker-2 status-1 priority-4 priority-default" title="Feature: Shorter syntax for anonymous refinements (Open)" href="https://redmine.ruby-lang.org/issues/16241">#16241</a>, is to make them as lightweight-feeling as possible. This is what feels "intuitively enough" to refine something:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">refine</span> <span class="no">Something</span> <span class="k">do</span>
<span class="k">def</span> <span class="nf">foo</span>
<span class="c1">#...</span>
</code></pre>
<p>Everything that tries to be more formalistic, just raises the bar of "shouldn't I do a small refinement here?.." (well, somebody might argue that this bar should be high, but then what's the point of refinements?)</p>
<p>So, for me "let's nest it in one more <code>using</code> for better organization" seems annoyingly redundant and un-Ruby-ish (like, there are many things that can be nested in more blocks for "better organization", like <code>attributes do ... end</code> or <code>private_methods do ... end</code>, or <code>constants do ... end</code>, but we don't do this, right? And if somebody wants to logically structure stuff, they do it with comments/order/non-code means)</p>