ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:95234] [Ruby master Feature#16241] Shorter syntax for anonymous refinements
       [not found] <redmine.issue-16241.20191005190403@ruby-lang.org>
@ 2019-10-05 19:04 ` dementiev.vm
  2019-10-05 22:05 ` [ruby-core:95236] " zverok.offline
  2019-10-05 22:40 ` [ruby-core:95237] " shevegen
  2 siblings, 0 replies; 3+ messages in thread
From: dementiev.vm @ 2019-10-05 19:04 UTC (permalink / raw)
  To: ruby-core

Issue #16241 has been reported by palkan (Vladimir Dementyev).

----------------------------------------
Feature #16241: Shorter syntax for anonymous refinements
https://bugs.ruby-lang.org/issues/16241

* Author: palkan (Vladimir Dementyev)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The original discussion is here https://bugs.ruby-lang.org/issues/14344.

tl;dr
- Refinements are often used in-place with anonymous modules
- Having shorter syntax could lower the barrier of entry for Rubyist wanting to explore this feature
- Previous syntax suggestions were not accepted.


I suggest adding a shorter syntax (technically, API):

```ruby
# before
using(Module.new do
  refine Array do
    def foo;"bar";end
  end
end)

# after
refining Array do
  def foo; "bar"; end
end
```

The original idea was to use `using_refined` instead of `refining` but after discussing with Matz we decided that it's too verbose, and `refining` seems better. But is it good enough? Any thoughts?




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:95236] [Ruby master Feature#16241] Shorter syntax for anonymous refinements
       [not found] <redmine.issue-16241.20191005190403@ruby-lang.org>
  2019-10-05 19:04 ` [ruby-core:95234] [Ruby master Feature#16241] Shorter syntax for anonymous refinements dementiev.vm
@ 2019-10-05 22:05 ` zverok.offline
  2019-10-05 22:40 ` [ruby-core:95237] " shevegen
  2 siblings, 0 replies; 3+ messages in thread
From: zverok.offline @ 2019-10-05 22:05 UTC (permalink / raw)
  To: ruby-core

Issue #16241 has been updated by zverok (Victor Shepelev).


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, [here](https://github.com/zverok/drosterize) and [here](https://github.com/zverok/xkcdize) 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". 

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 `using Geometry` with ton of specific geometry-related services added to numbers and matrices and whatnot).

----------------------------------------
Feature #16241: Shorter syntax for anonymous refinements
https://bugs.ruby-lang.org/issues/16241#change-81909

* Author: palkan (Vladimir Dementyev)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The original discussion is here https://bugs.ruby-lang.org/issues/14344.

tl;dr
- Refinements are often used in-place with anonymous modules
- Having shorter syntax could lower the barrier of entry for Rubyist wanting to explore this feature
- Previous syntax suggestions were not accepted.


I suggest adding a shorter syntax (technically, API):

```ruby
# before
using(Module.new do
  refine Array do
    def foo;"bar";end
  end
end)

# after
refining Array do
  def foo; "bar"; end
end
```

The original idea was to use `using_refined` instead of `refining` but after discussing with Matz we decided that it's too verbose, and `refining` seems better. But is it good enough? Any thoughts?




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:95237] [Ruby master Feature#16241] Shorter syntax for anonymous refinements
       [not found] <redmine.issue-16241.20191005190403@ruby-lang.org>
  2019-10-05 19:04 ` [ruby-core:95234] [Ruby master Feature#16241] Shorter syntax for anonymous refinements dementiev.vm
  2019-10-05 22:05 ` [ruby-core:95236] " zverok.offline
@ 2019-10-05 22:40 ` shevegen
  2 siblings, 0 replies; 3+ messages in thread
From: shevegen @ 2019-10-05 22:40 UTC (permalink / raw)
  To: ruby-core

Issue #16241 has been updated by shevegen (Robert A. Heiler).


Hmm. I think there was another suggestion some months ago that also suggested
simplifications or "beautification" in regards to refinements.

In general I like ideas that try to make the refinement feature more accessible.

Syntax has been the major reason why I have not been using refinements in my own
code; oddly enough, I 100% agree that it is a good idea to have refinements, but
the syntax always felt ... clunky to me. That is mostly my reasoning why I think
simplifications would be nice.

Matz provided a good syntactic "base". For example, to subclass, we do:

   class Foo < Bar

That's very expressive and short.

Refinements on the other hand always felt a bit too verbose to me. That may be 
a personal choice/preference, granted; on the other hand, looking at suggestions
to simplify or beautify it, it does not seem to be a unique opinion as such. :)

(I also have to admit that I once assumed for refinements to work differently,
until I read up on the original proposal. I think a few other ruby users may
have also mis-interpreted how refinements work now and then. I mention this
in particular because I believe matz and the core team would like to have 
clear definitions for any specifications related to refinements.)

I am still not necessarily in big favour of using the word "refining"; it 
also seems not as good as the "Foo < Bar" notation :) - but on the other hand,
this is, I think, still an improvement over the even more (!) verbose variant
that you gave as an example.

By the way, I also completely agree with you here:

> Having shorter syntax could lower the barrier of entry for Rubyist
> wanting to explore this feature

I think simple/expressive syntax can help a LOT.

I think the only complaint I have about "refining" is that the word seems a 
bit strange to me ... I do not have a better name as suggestion, though.

By the way, would we then have two words? E. g. "refine" and "refining"?
Because this may lead to confusion; may be better to settle just on one
either way. (Or perhaps, if that requires modifications and deprecations,
to aim for ruby 4.0 with that, but with simplification as the primary
goal.)

zverok wrote:

> 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". 

Yup, I agree.

> So, "inplace refinements" is probably the main kind of refinements
> the developer could care; while "refinements in a module"

I think we have to be careful here to not make refinements more complicated
or complex, or add more than one refinements in place. This is, I think,
what is good about the proposal here in principle, since the primary (or
sole) aim appears to be to lead to a lighter syntax, which I think would
be good, even if the semantics remain the same in regards to refinements.

If possible, anyone able to come up with other names or syntax could 
add a comment or two in regards to the word "refining". I personally have
not fully made up my mind yet; I am not in favour or disfavour of the
word per se. I think the only statement I can make is that it seems to
be better than the older/current variant. But perhaps I am overlooking
something; may need someone who has used refinements in the past (I
can not remember that other issue where someone has suggested a 
simplification syntax-wise some months ago ...)

----------------------------------------
Feature #16241: Shorter syntax for anonymous refinements
https://bugs.ruby-lang.org/issues/16241#change-81910

* Author: palkan (Vladimir Dementyev)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The original discussion is here https://bugs.ruby-lang.org/issues/14344.

tl;dr
- Refinements are often used in-place with anonymous modules
- Having shorter syntax could lower the barrier of entry for Rubyist wanting to explore this feature
- Previous syntax suggestions were not accepted.


I suggest adding a shorter syntax (technically, API):

```ruby
# before
using(Module.new do
  refine Array do
    def foo;"bar";end
  end
end)

# after
refining Array do
  def foo; "bar"; end
end
```

The original idea was to use `using_refined` instead of `refining` but after discussing with Matz we decided that it's too verbose, and `refining` seems better. But is it good enough? Any thoughts?




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-05 22:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16241.20191005190403@ruby-lang.org>
2019-10-05 19:04 ` [ruby-core:95234] [Ruby master Feature#16241] Shorter syntax for anonymous refinements dementiev.vm
2019-10-05 22:05 ` [ruby-core:95236] " zverok.offline
2019-10-05 22:40 ` [ruby-core:95237] " shevegen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).