ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:84778] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
@ 2018-01-09 15:54 ` kevin.deisz
  2018-01-09 16:38 ` [ruby-core:84779] " shevegen
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: kevin.deisz @ 2018-01-09 15:54 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been reported by kddeisz (Kevin Deisz).

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:84779] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
  2018-01-09 15:54 ` [ruby-core:84778] [Ruby trunk Feature#14344] refine at class level kevin.deisz
@ 2018-01-09 16:38 ` shevegen
  2018-01-09 17:13 ` [ruby-core:84780] " eregontp
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: shevegen @ 2018-01-09 16:38 UTC (permalink / raw)
  To: ruby-core

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


I like the proposed syntax. Syntax is one major reason for
me, oddly enough, to not use refinements. In particular the
"using" clause felt weird, so I like changes (improvements?)
to the syntax.

I think your syntax suggestion is better than the status quo
too.

However had, I am saying all of this without really having
used refinements extensively (other than in test.rb files),
so I am essentially not qualified to comment really. I'd
be inclined to use your suggestion more than the "using"
variant, though. ;)

(There was some presentation at ruby or railsconf about 
someone talking about nobody using refinements or so, 
a few years ago perhaps. A bit like the old "nobody knows
nobu", which isn't true by now anymore either. Either way
I think people should comment who use refinements a lot
too, since they should be able to consider the impact of
the changed syntax proposal.)

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-69495

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:84780] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
  2018-01-09 15:54 ` [ruby-core:84778] [Ruby trunk Feature#14344] refine at class level kevin.deisz
  2018-01-09 16:38 ` [ruby-core:84779] " shevegen
@ 2018-01-09 17:13 ` eregontp
  2018-01-09 17:19 ` [ruby-core:84781] " kevin.deisz
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: eregontp @ 2018-01-09 17:13 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by Eregon (Benoit Daloze).


The whole purpose of the Module around it is so multiple refinements can be bundled up together in a Module and that Module is passed to #using.

I don't think #refine should enable refinements after the block.
It doesn't seem clear to me and is too confusing with the existing usage of #refine.
Whether #refine is called on a Module or not would have very different semantics.

Also I guess in general refinements are not defined right in the class using them, especially if they are not trivial one-liner methods.

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-69496

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:84781] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2018-01-09 17:13 ` [ruby-core:84780] " eregontp
@ 2018-01-09 17:19 ` kevin.deisz
  2018-01-09 17:26 ` [ruby-core:84782] " eregontp
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: kevin.deisz @ 2018-01-09 17:19 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by kddeisz (Kevin Deisz).


I think we're talking about two different use cases. There is a place for refinements with large batch changes and a module is very appropriate for that. But for smaller refinements, which make life a lot easier, it's really not that far of a stretch. It's not that much different from `class Foobar ... end` being a shortcut for `Foobar = Class.new do ... end`


----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-69497

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:84782] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2018-01-09 17:19 ` [ruby-core:84781] " kevin.deisz
@ 2018-01-09 17:26 ` eregontp
  2018-01-09 17:31 ` [ruby-core:84783] " zverok.offline
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: eregontp @ 2018-01-09 17:26 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by Eregon (Benoit Daloze).


There is probably room for a shorter syntax for refinements.
But one thing which is not acceptable in this specific proposition here is that

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
  # String refinements apply here
end
~~~

and

~~~ ruby
module Test
  refine String do
    def refined?
      true
    end
  end
  # String refinements do not apply here, it's a normal Module#refine
end
~~~

would do two very different things, which is too hard to understand and confusing.

Maybe a block to #using would make things slightly shorter:

~~~ ruby
class Test
  using do
    refine String do
      def refined?
        true
      end
    end
  end
end
~~~

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-69498

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:84783] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2018-01-09 17:26 ` [ruby-core:84782] " eregontp
@ 2018-01-09 17:31 ` zverok.offline
  2018-01-10 16:06 ` [ruby-core:84814] " kevin.deisz
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: zverok.offline @ 2018-01-09 17:31 UTC (permalink / raw)
  To: ruby-core

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


> Also I guess in general refinements are not defined right in the class using them, especially if they are not trivial one-liner methods.

I believe that "one-liner" & "inplace" definition is one of the most important usages of refinements.

Because, speaking philosophically, why do we need them at all? 

Instead of doing "`refine String` + call `string.something`" you always can `StringUtilModule.something(string)`, but when you do some, say, complicated reporting algorithm, those `StringUtilModule.something(string)`, especially several in a row can become REALLY ugly. 

Therefore you just... add one small method to `String`. Just here and there, as close to its usage and as visible and as easy as possible, and it WILL be one-line method, just calling the same `StringUtilModule.something(string)` (which is easier to test and maintain and document).

I believe that "module with refinement for the several classes" is, to the opposite, much less frequent case. It is either "all cool shticks for my entire project in one file", or something very domain-specific (like, I don't know, `String#as_currency`, `Numeric#as_money(currency)`, `CSV#ready_money` something).

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-69499

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:84814] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2018-01-09 17:31 ` [ruby-core:84783] " zverok.offline
@ 2018-01-10 16:06 ` kevin.deisz
  2018-01-10 18:05 ` [ruby-core:84818] " eregontp
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: kevin.deisz @ 2018-01-10 16:06 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by kddeisz (Kevin Deisz).


Just to take a real example from my current application, here's a job (from Rails ActiveJob) that I want to refine by moving the logic into the class in which it belongs. It currently looks like this:

~~~ruby
class EventEndActionsJob < ApplicationJob
  queue_as :default

  def perform(event)
    return if event.end_actions_completed?
    event.update!(end_actions_completed: true)
    activate_survey_for(event) if event.survey
  end

  private

  def activate_survey_for(event)
    event.survey.update!(active: true)

    event.rsvps.not_declined.each do |rsvp|
      EmailJob.perform_later('PostEventSurvey', rsvp)
    end
  end
end
~~~

but I want it to look like this:

~~~ ruby
class EventEndActionsJob < ApplicationJob
  refine Event do
    def perform_end_actions
      return if end_actions_completed?

      update!(end_actions_completed: true)
      activate_survey if survey
    end

    private

    def activate_survey
      survey.update!(active: true)

      rsvps.not_declined.each do |rsvp|
        EmailJob.perform_later('PostEventSurvey', rsvp)
      end
    end
  end

  queue_as :default

  def perform(event)
    event.perform_end_actions
  end
end
~~~

now all of the logic is in the right place (in the Event model) but I don't have to clutter up the class definition with a method that will only be used in this one place. I don't need to refine multiple classes, so I don't want to build a whole module, but instead right now I have to:

~~~ruby
class EventEndActionsJob < ApplicationJob
  using(
    Module.new do
      refine Event do
        def perform_end_actions
          return if end_actions_completed?

          update!(end_actions_completed: true)
          activate_survey if survey
        end

        private

        def activate_survey
          survey.update!(active: true)

          rsvps.not_declined.each do |rsvp|
            EmailJob.perform_later('PostEventSurvey', rsvp)
          end
        end
      end
    end
  )

  queue_as :default

  def perform(event)
    event.perform_end_actions
  end
end
~~~

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-69528

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:84818] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2018-01-10 16:06 ` [ruby-core:84814] " kevin.deisz
@ 2018-01-10 18:05 ` eregontp
  2018-01-10 18:22 ` [ruby-core:84819] " kevin.deisz
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: eregontp @ 2018-01-10 18:05 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by Eregon (Benoit Daloze).


kddeisz (Kevin Deisz) wrote:
> Just to take a real example from my current application, here's a job (from Rails ActiveJob) that I want to refine by moving the logic into the class in which it belongs. It currently looks like this:

That's an interesting example indeed: using refinements to not pollute the model class but still make it convenient to write methods with the model as `self`.

To clarify my comment above: I'm not against a shorter way to define refinements+use them.
But #refine as proposed is wrong: if EventEndActionsJob was a module it would stop working because then
it would be the refine-just-define-refinements (current semantics) and not the refine-define-and-use-refinements you propose.

Or are you proposing to change the behavior of `refine do ... end` to always enable refinements after it until the end of the class/module body or the end of the file?
Then there would be a compatibility risk.

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-69531

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:84819] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2018-01-10 18:05 ` [ruby-core:84818] " eregontp
@ 2018-01-10 18:22 ` kevin.deisz
  2018-04-11 14:45 ` [ruby-core:86511] " kevin.deisz
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: kevin.deisz @ 2018-01-10 18:22 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by kddeisz (Kevin Deisz).


I was proposing the former, which would be to have `refine` be a class method that would effectively be the same as `using` with an anonymous module. I get what you're saying about it being different between a class and a module but I'm not sure I necessary see that as a problem. Class and Module already don't have perfect parity (allocate, new, superclass) so it doesn't seem like we need to enforce that. I doubt people would be caught off guard by a change in the semantics of the method between Module and Class because it doesn't seem like it would be a common practice to be switching constants back and forth between modules and classes all the time.

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-69532

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:86511] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2018-01-10 18:22 ` [ruby-core:84819] " kevin.deisz
@ 2018-04-11 14:45 ` kevin.deisz
  2018-04-16 10:03 ` [ruby-core:86550] " eregontp
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: kevin.deisz @ 2018-04-11 14:45 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by kddeisz (Kevin Deisz).


I haven't contributed before so I'm not sure how to bump this ticket, but I'd like to keep pushing on this. Could someone from core take a look at this proposal? I'd love to help introduce this syntax.

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-71453

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:86550] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2018-04-11 14:45 ` [ruby-core:86511] " kevin.deisz
@ 2018-04-16 10:03 ` eregontp
  2018-04-17 15:38 ` [ruby-core:86561] " kevin.deisz
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: eregontp @ 2018-04-16 10:03 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by Eregon (Benoit Daloze).


I am a MRI committer. This is just my opinion, but I'm confident it is shared by other committers as well.

I believe changing the semantics of `refine` (to be using+Module.new+refine) based on whether the receiver is a Class or Module is not acceptable.
So, we need a new name for this feature as `refine` would be too confusing with the existing semantics.

Changing the semantics for `refine` for all cases would be consistent, but introduce too large incompatibilities.
So a new name seems the way forward, do you have a suggestion?

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-71490

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:86561] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2018-04-16 10:03 ` [ruby-core:86550] " eregontp
@ 2018-04-17 15:38 ` kevin.deisz
  2019-01-02 22:41 ` [ruby-core:90864] " dementiev.vm
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: kevin.deisz @ 2018-04-17 15:38 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by kddeisz (Kevin Deisz).


Thanks Benoit. A couple of suggestions would be:

~~~
anonymous_refine
inline_refine
class_refine
refining
refine_class
~~~

Any of these would be fine I think - `anonymous_refine` gets across that it's creating an anonymous module that will be used. `inline_refine` is similar in that sense. `class_refine` may be confusing in that it's not going up to the singleton class and refining. `refining` is inline with Rails' `concerning`, but doesn't particularly convey special meaning. `refine_class` gets across that it's only refining a specific class, which I kind of like the best. 

Would something like `refine_class` be amenable to the core team? 

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-71502

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:90864] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2018-04-17 15:38 ` [ruby-core:86561] " kevin.deisz
@ 2019-01-02 22:41 ` dementiev.vm
  2019-01-11 11:05 ` [ruby-core:91018] " shevegen
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: dementiev.vm @ 2019-01-02 22:41 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by palkan (Vladimir Dementyev).


I'm also also using refinements a lot and in most cases I use "inlined" refinements, so would be glad to have a shorter syntax (and, actually, have been thinking about it for a long time and was going to propose a feature–and found this ticket).

I was thinking about a syntax proposed by Benoit:

```ruby
using do
  refine Array do 
    # ...
  end
end
```

> I believe changing the semantics of refine (to be using+Module.new+refine) based on whether the receiver is a Class or Module is not acceptable.

What if we change it only for top-level `refine`?

```ruby
# this works
refine String do
  # ...
end

module Something
  # this raises an exception
  refine ...
end

class AnotherThing
  # and this raises
  refine ...
end
```

This could be implemented just as syntactic sugar (by defining a `refine` method on vm top).




----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-76049

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:91018] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (12 preceding siblings ...)
  2019-01-02 22:41 ` [ruby-core:90864] " dementiev.vm
@ 2019-01-11 11:05 ` shevegen
  2019-01-11 16:04 ` [ruby-core:91026] " dementiev.vm
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: shevegen @ 2019-01-11 11:05 UTC (permalink / raw)
  To: ruby-core

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


I think that:

    using do
      refine Array do 

Is not good. It looks very strange to me.

The other variants, such as the original one:

    class Test
      refine String do

or just toplevel:

    refine String do

would seem better to me.

It may be best to have matz pick a syntax, if he agrees with the feature. :)

(May have to then also update documentation and specification of 
refinements; I remember that I was once surprised thinking that I 
knew the original definition but upon re-reading it, I realized that 
my assumption was not completely correct.)

(On a side note, I think you added it to the recent developer meeting
which already happened; may have to add it to the next one or
just have it be a carry-over to the next meeting.)

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-76243

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:91026] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (13 preceding siblings ...)
  2019-01-11 11:05 ` [ruby-core:91018] " shevegen
@ 2019-01-11 16:04 ` dementiev.vm
  2019-02-07  6:35 ` [ruby-core:91452] " matz
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 18+ messages in thread
From: dementiev.vm @ 2019-01-11 16:04 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by palkan (Vladimir Dementyev).


shevegen (Robert A. Heiler) wrote:
> I think that:
> 
>     using do
>       refine Array do 
> 
> Is not good. It looks very strange to me.

On the other hand, it's closer to what we have to write now (`using(Module.new do`) and it doesn't have any additional constraints like being at the top level of class/module context dependent.

> 
> The other variants, such as the original one:
> 
>     class Test
>       refine String do
> 

The problem with this approach has been already mentioned by Benoit  ([[https://bugs.ruby-lang.org/issues/14344#note-7]]): the behaviour of `refine` changes depending on whether we're in the module or class context.

IMO, it would introduce even more confusion. And the goal of this feature, as it has been said, is to lower the barrier.

> (On a side note, I think you added it to the recent developer meeting
> which already happened)

Oops, I got lost in time) thanks for noticing!

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-76248

* Author: kddeisz (Kevin Deisz)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:91452] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (14 preceding siblings ...)
  2019-01-11 16:04 ` [ruby-core:91026] " dementiev.vm
@ 2019-02-07  6:35 ` matz
  2019-02-07 21:13 ` [ruby-core:91482] " dementiev.vm
  2019-02-07 22:14 ` [ruby-core:91483] " matz
  17 siblings, 0 replies; 18+ messages in thread
From: matz @ 2019-02-07  6:35 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Rejected

I understand the need. But I cannot accept the proposed syntax for two reasons.

(1) the original proposal using `refine` for classes, which is confusing with `refine` in refinement modules.
(2) the modified syntax `using do` is also confusing. The scope of refinement may be in the block or the surrounding scope.

Matz.
 

----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-76712

* Author: kddeisz (Kevin Deisz)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:91482] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (15 preceding siblings ...)
  2019-02-07  6:35 ` [ruby-core:91452] " matz
@ 2019-02-07 21:13 ` dementiev.vm
  2019-02-07 22:14 ` [ruby-core:91483] " matz
  17 siblings, 0 replies; 18+ messages in thread
From: dementiev.vm @ 2019-02-07 21:13 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by palkan (Vladimir Dementyev).


matz (Yukihiro Matsumoto) wrote:
> I understand the need. But I cannot accept the proposed syntax for two reasons.
> 
> (1) the original proposal using `refine` for classes, which is confusing with `refine` in refinement modules.
> (2) the modified syntax `using do` is also confusing. The scope of refinement may be in the block or the surrounding scope.
> 
> Matz.

Thanks!

Since this has been marked as rejected, should we propose alternatives in a new ticket or could we continue discussing here?


----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-76741

* Author: kddeisz (Kevin Deisz)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

* [ruby-core:91483] [Ruby trunk Feature#14344] refine at class level
       [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
                   ` (16 preceding siblings ...)
  2019-02-07 21:13 ` [ruby-core:91482] " dementiev.vm
@ 2019-02-07 22:14 ` matz
  17 siblings, 0 replies; 18+ messages in thread
From: matz @ 2019-02-07 22:14 UTC (permalink / raw)
  To: ruby-core

Issue #14344 has been updated by matz (Yukihiro Matsumoto).


@palkan, yes, post a new issue, when you come up with a new idea.

Matz.


----------------------------------------
Feature #14344: refine at class level
https://bugs.ruby-lang.org/issues/14344#change-76742

* Author: kddeisz (Kevin Deisz)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I rely on refinements a lot, but don't want to keep writing `Module.new` in code. I'm proposing `Object::refine`, which would create an anonymous module behind the scenes with equivalent functionality. So:

~~~ ruby
class Test
  using Module.new {
    refine String do
      def refined?
        true
      end
    end
  }
end
~~~

would become

~~~ ruby
class Test
  refine String do
    def refined?
      true
    end
  end
end
~~~

It's a small change, but reads a lot more clearly. Thoughts?



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

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

end of thread, other threads:[~2019-02-07 22:15 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-14344.20180109155454@ruby-lang.org>
2018-01-09 15:54 ` [ruby-core:84778] [Ruby trunk Feature#14344] refine at class level kevin.deisz
2018-01-09 16:38 ` [ruby-core:84779] " shevegen
2018-01-09 17:13 ` [ruby-core:84780] " eregontp
2018-01-09 17:19 ` [ruby-core:84781] " kevin.deisz
2018-01-09 17:26 ` [ruby-core:84782] " eregontp
2018-01-09 17:31 ` [ruby-core:84783] " zverok.offline
2018-01-10 16:06 ` [ruby-core:84814] " kevin.deisz
2018-01-10 18:05 ` [ruby-core:84818] " eregontp
2018-01-10 18:22 ` [ruby-core:84819] " kevin.deisz
2018-04-11 14:45 ` [ruby-core:86511] " kevin.deisz
2018-04-16 10:03 ` [ruby-core:86550] " eregontp
2018-04-17 15:38 ` [ruby-core:86561] " kevin.deisz
2019-01-02 22:41 ` [ruby-core:90864] " dementiev.vm
2019-01-11 11:05 ` [ruby-core:91018] " shevegen
2019-01-11 16:04 ` [ruby-core:91026] " dementiev.vm
2019-02-07  6:35 ` [ruby-core:91452] " matz
2019-02-07 21:13 ` [ruby-core:91482] " dementiev.vm
2019-02-07 22:14 ` [ruby-core:91483] " matz

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