https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112019-10-05T22:05:58ZRuby Issue Tracking SystemRuby master - Feature #16241: Shorter syntax for anonymous refinementshttps://bugs.ruby-lang.org/issues/16241?journal_id=819092019-10-05T22:05:58Zzverok (Victor Shepelev)zverok.offline@gmail.com
<ul></ul><p>I believe that is really super-good thing. As I've written elsewhere in this tracker, the most useful case for refinements is "in current module, I want some shortcuts for my code to look cleaner". For example, <a href="https://github.com/zverok/drosterize" class="external">here</a> and <a href="https://github.com/zverok/xkcdize" class="external">here</a> I experimented with representing some graphics algorithm in a most "readable" way, adding really small methods to core (Numeric) and RMagick objects. The point is "here, in this module, I crave for some things to exists in some objects".</p>
<p>So, "inplace refinements" is probably the main kind of refinements the developer could care; while "refinements in a module" could be used, probably, for some "more hygienic" ActiveSupport-alike gems, or some specific blends of Ruby (like <code>using Geometry</code> with ton of specific geometry-related services added to numbers and matrices and whatnot).</p> Ruby master - Feature #16241: Shorter syntax for anonymous refinementshttps://bugs.ruby-lang.org/issues/16241?journal_id=819102019-10-05T22:40:38Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>Hmm. I think there was another suggestion some months ago that also suggested<br>
simplifications or "beautification" in regards to refinements.</p>
<p>In general I like ideas that try to make the refinement feature more accessible.</p>
<p>Syntax has been the major reason why I have not been using refinements in my own<br>
code; oddly enough, I 100% agree that it is a good idea to have refinements, but<br>
the syntax always felt ... clunky to me. That is mostly my reasoning why I think<br>
simplifications would be nice.</p>
<p>Matz provided a good syntactic "base". For example, to subclass, we do:</p>
<p>class Foo < Bar</p>
<p>That's very expressive and short.</p>
<p>Refinements on the other hand always felt a bit too verbose to me. That may be<br>
a personal choice/preference, granted; on the other hand, looking at suggestions<br>
to simplify or beautify it, it does not seem to be a unique opinion as such. :)</p>
<p>(I also have to admit that I once assumed for refinements to work differently,<br>
until I read up on the original proposal. I think a few other ruby users may<br>
have also mis-interpreted how refinements work now and then. I mention this<br>
in particular because I believe matz and the core team would like to have<br>
clear definitions for any specifications related to refinements.)</p>
<p>I am still not necessarily in big favour of using the word "refining"; it<br>
also seems not as good as the "Foo < Bar" notation :) - but on the other hand,<br>
this is, I think, still an improvement over the even more (!) verbose variant<br>
that you gave as an example.</p>
<p>By the way, I also completely agree with you here:</p>
<blockquote>
<p>Having shorter syntax could lower the barrier of entry for Rubyist<br>
wanting to explore this feature</p>
</blockquote>
<p>I think simple/expressive syntax can help a LOT.</p>
<p>I think the only complaint I have about "refining" is that the word seems a<br>
bit strange to me ... I do not have a better name as suggestion, though.</p>
<p>By the way, would we then have two words? E. g. "refine" and "refining"?<br>
Because this may lead to confusion; may be better to settle just on one<br>
either way. (Or perhaps, if that requires modifications and deprecations,<br>
to aim for ruby 4.0 with that, but with simplification as the primary<br>
goal.)</p>
<p>zverok wrote:</p>
<blockquote>
<p>As I've written elsewhere in this tracker, the most useful case for<br>
refinements is "in current module, I want some shortcuts for my<br>
code to look cleaner".</p>
</blockquote>
<p>Yup, I agree.</p>
<blockquote>
<p>So, "inplace refinements" is probably the main kind of refinements<br>
the developer could care; while "refinements in a module"</p>
</blockquote>
<p>I think we have to be careful here to not make refinements more complicated<br>
or complex, or add more than one refinements in place. This is, I think,<br>
what is good about the proposal here in principle, since the primary (or<br>
sole) aim appears to be to lead to a lighter syntax, which I think would<br>
be good, even if the semantics remain the same in regards to refinements.</p>
<p>If possible, anyone able to come up with other names or syntax could<br>
add a comment or two in regards to the word "refining". I personally have<br>
not fully made up my mind yet; I am not in favour or disfavour of the<br>
word per se. I think the only statement I can make is that it seems to<br>
be better than the older/current variant. But perhaps I am overlooking<br>
something; may need someone who has used refinements in the past (I<br>
can not remember that other issue where someone has suggested a<br>
simplification syntax-wise some months ago ...)</p> Ruby master - Feature #16241: Shorter syntax for anonymous refinementshttps://bugs.ruby-lang.org/issues/16241?journal_id=819242019-10-06T19:15:09ZEregon (Benoit Daloze)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-6 priority-4 priority-default closed" href="/issues/14344">Feature #14344</a>: refine at class level</i> added</li></ul> Ruby master - Feature #16241: Shorter syntax for anonymous refinementshttps://bugs.ruby-lang.org/issues/16241?journal_id=886502020-11-20T17:00:58Zk0kubun (Takashi Kokubun)takashikkbn@gmail.com
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/17336">Feature #17336</a>: using refined: do ... end</i> added</li></ul> Ruby master - Feature #16241: Shorter syntax for anonymous refinementshttps://bugs.ruby-lang.org/issues/16241?journal_id=886572020-11-20T19:22:30ZEregon (Benoit Daloze)
<ul></ul><p>This sounds fine to me.</p>
<p>I think <code>using do; refine Array do; ...; end; end</code> would be a good way too (<a href="https://bugs.ruby-lang.org/issues/17336#note-6" class="external">https://bugs.ruby-lang.org/issues/17336#note-6</a>), but matz thinks it's confusing whether the block is for defining refinements or for using refinements, and whether refinements apply after (<a href="https://bugs.ruby-lang.org/issues/14344#note-15" class="external">https://bugs.ruby-lang.org/issues/14344#note-15</a>).</p> Ruby master - Feature #16241: Shorter syntax for anonymous refinementshttps://bugs.ruby-lang.org/issues/16241?journal_id=943812021-10-28T11:13:24ZEregon (Benoit Daloze)
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-6 priority-4 priority-default closed" href="/issues/11919">Feature #11919</a>: Passing a module directly </i> added</li></ul>