Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private method support #593

Open
st0012 opened this issue Feb 13, 2018 · 5 comments
Open

Private method support #593

st0012 opened this issue Feb 13, 2018 · 5 comments

Comments

@st0012
Copy link
Member

st0012 commented Feb 13, 2018

  • As @hachi8833 suggested, we're going to support private method using _ prefix instead of private keyword. And
  • protect won't be support.
  • Users can override private methods
  • Users can't use send to call private methods
@64kramsystem
Copy link
Member

64kramsystem commented Feb 13, 2018

protect won't be support.

can you elaborate a bit on the private Goby visibility? will it have the exact same specification as Ruby?

using the exact same specification would, for example, disallow calling private methods of an instance of a given class, from another instance of the same class.

this is fine, although I think it should be designed very carefully. protected access level is in fact designed, in Ruby, to allow the behavior above, although, at the same time, Ruby has a very different (much more liberal) idea of public/private compared to, say, Java.

@hachi8833
Copy link
Member

According to https://twitter.com/yukihiro_matz/status/180090910451834881, Matz feels that protected is redundant and says that he would not have adopted it if he could have. https://twitter.com/yukihiro_matz/status/180087810823438337 says that the keyword protected was added after adopting private, and it made developers from Java/C++ pretty confused. Considering this, protected feature looks unnecessary for Goby.

@hachi8833
Copy link
Member

Personally, prohibiting the overriding ancestor classes's private _ methods is preferable for me: if descendant classes would unexpectedly overrides the ancestor's private _ methods, it would cause unexpected behaviors. Instead, unrestricted send can be a last resort to access any methods including private _ methods.

Using private _ is very easy and I expect this would promote appropriate protection on developer's codes. In other words, private _ might increase the chances of unexpected overriding.

Using send is rather intentional for developers and I hope this is not so easy to be exploited.
(Longer method name like force_send or send_message might be better to mitigate the exploitation)

Of course I respect @st0012's final decision 😄

FYI: Ruby's specification for private is actually under influence of Smalltalk and just an indication that the method is for private use and not recommended for direct calling, according to https://twitter.com/yukihiro_matz/status/180083650413596672. (Of course send can go beyond the restriction)

@64kramsystem
Copy link
Member

64kramsystem commented Feb 15, 2018

I'm personally fine with any solution.

The crucial concept is that it's made clear that under the stated conditions:

  • using the Ruby semantics of private method accessibility
  • no protected method accessibility
  • no calls, via send, to private method

it's acceptable that the following code is impossible to run:

class Sphere
  def bigger_than?(other)
    volume_in_internal_measure_unit > other.volume_in_internal_measure_unit
  end

  # following is private method
  def volume_in_internal_measure_unit
    some_calculation + some_constant
  end
end

this is acceptable, it's just a design choice to keep in mind. Ruby, for example, tends to be more "public" in terms of methods accessibility, than Java (this example of private method call is very frequent in Java).

@st0012 st0012 added this to the version 0.2.0 milestone Feb 14, 2020
@st0012
Copy link
Member Author

st0012 commented Feb 14, 2020

Will implement this in version 0.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants