Use pattern to define private method by default

I find it interesting how many elaborate ordering schemes for methods
seem to be around. I usually only have a block of public methods at
the top and private methods at the bottom. Other than that I don't
employ a particular scheme. Put differently: the need for such a
scheme could be an indication that classes have too many methods on
average. :slight_smile:

Kind regards

robert

ยทยทยท

On Fri, Jan 13, 2017 at 4:43 PM, Andy Jones <Andy.Jones@jameshall.co.uk> wrote:

The API reference should be the documentation.
If you look at proper documented ruby code like Rails code base you will see that your option of putting public methods all together makes no difference for that purpose.
<<<<

Well, we weren't talking about documentation, but that's an interesting point. Are you saying that the order of the methods in the class doesn't matter, because the rdoc/yard web pages ignore them? You might be right -- but we both still prefer to order methods in the class in a particular way, don't we?

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

What's the advantage of making them private in the first place? You can
always get around it with `send`. Unless dynamically looking up methods, it
really just serves as a guideline to developers that "hey, this is method
private to this class." So just using your naming convention should
suffice, without need to alter functionality.

ยทยทยท

On Fri, Jan 13, 2017 at 9:24 AM, Daniel Ferreira <subtileos@gmail.com> wrote:

Hi Robert,

On Fri, 13 Jan 2017 at 17:18, Robert Klemme <shortcutter@googlemail.com> > wrote:

On Fri, Jan 13, 2017 at 4:43 PM, Andy Jones <Andy.Jones@jameshall.co.uk> >> wrote:

>>>>>

> The API reference should be the documentation.

> If you look at proper documented ruby code like Rails code base you
will see that your option of putting public methods all together makes no
difference for that purpose.

> <<<<

>

> Well, we weren't talking about documentation, but that's an interesting
point. Are you saying that the order of the methods in the class doesn't
matter, because the rdoc/yard web pages ignore them? You might be right --
but we both still prefer to order methods in the class in a particular way,
don't we?

I find it interesting how many elaborate ordering schemes for methods

seem to be around. I usually only have a block of public methods at

the top and private methods at the bottom. Other than that I don't

employ a particular scheme. Put differently: the need for such a

scheme could be an indication that classes have too many methods on

average. :slight_smile:

Kind regards

robert

--

[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can

- without end}

http://blog.rubybestpractices.com/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>

<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

When we start to implement a public method and extend the class with it

then we need to go down and right the private method.

It is time consuming.
Also it is harder to refactor.

If you have public and private method together you pick them up and create
the new class without any problem. Just by delegating the public method
into the new class object.

There are other things I can point out as advantages.

Thanks,

Daniel Ferreira (Subtileos)

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Hi Robert,

>>>>>

> The API reference should be the documentation.

> If you look at proper documented ruby code like Rails code base you will
see that your option of putting public methods all together makes no
difference for that purpose.

> <<<<

>

> Well, we weren't talking about documentation, but that's an interesting
point. Are you saying that the order of the methods in the class doesn't
matter, because the rdoc/yard web pages ignore them? You might be right --
but we both still prefer to order methods in the class in a particular way,
don't we?

I find it interesting how many elaborate ordering schemes for methods

seem to be around. I usually only have a block of public methods at

the top and private methods at the bottom. Other than that I don't

employ a particular scheme. Put differently: the need for such a

scheme could be an indication that classes have too many methods on

average. :slight_smile:

Kind regards

robert

--

[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can

- without end}

http://blog.rubybestpractices.com/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>

<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

When we start to implement a public method and extend the class with it

then we need to go down and right the private method.

It is time consuming.
Also it is harder to refactor.

If you have public and private method together you pick them up and create
the new class without any problem. Just by delegating the public method
into the new class object.

There are other things I can point out as advantages.

Thanks,

Daniel Ferreira (Subtileos)

ยทยทยท

On Fri, 13 Jan 2017 at 17:18, Robert Klemme <shortcutter@googlemail.com> wrote:

On Fri, Jan 13, 2017 at 4:43 PM, Andy Jones <Andy.Jones@jameshall.co.uk> > wrote:

Hi Ryan,

Thanks for your question.

What's the advantage of making them private in the first place? You can
always get around it with `send`. Unless dynamically looking up methods, it
really just serves as a guideline to developers that "hey, this is method
private to this class." So just using your naming convention should
suffice, without need to alter functionality.

Hi Robert,

The API reference should be the documentation.

If you look at proper documented ruby code like Rails code base you will

see that your option of putting public methods all together makes no
difference for that purpose.

<<<<

Well, we weren't talking about documentation, but that's an interesting

point. Are you saying that the order of the methods in the class doesn't
matter, because the rdoc/yard web pages ignore them? You might be right --
but we both still prefer to order methods in the class in a particular way,
don't we?

I find it interesting how many elaborate ordering schemes for methods

seem to be around. I usually only have a block of public methods at

the top and private methods at the bottom. Other than that I don't

employ a particular scheme. Put differently: the need for such a

scheme could be an indication that classes have too many methods on

average. :slight_smile:

Kind regards

robert

ยทยทยท

On Fri, 13 Jan 2017 at 19:47, Ryan Buckley <duhryguy@gmail.com> wrote:
On Fri, Jan 13, 2017 at 9:24 AM, Daniel Ferreira <subtileos@gmail.com> wrote:
On Fri, 13 Jan 2017 at 17:18, Robert Klemme <shortcutter@googlemail.com> wrote:
On Fri, Jan 13, 2017 at 4:43 PM, Andy Jones <Andy.Jones@jameshall.co.uk> wrote:

--

[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can

- without end}

http://blog.rubybestpractices.com/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>

<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

When we start to implement a public method and extend the class with it
then we need to go down and right the private method.

It is time consuming.
Also it is harder to refactor.

If you have public and private method together you pick them up and create
the new class without any problem. Just by delegating the public method
into the new class object.

There are other things I can point out as advantages.

Thanks,

Daniel Ferreira (Subtileos)

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>

<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>

<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

I believe the class public interface (API) should be only limited to the
methods strictly necessary to deliver the functionality.
Only these methods should be object of (unit/integration) tests and all
public methods should be object of those tests.
These are the simple rules.
Then I have more.
All public methods should have a clear documentation for their use cases.
Each classe should be designed with the API in mind and with the goal of
keeping it as small as possible.
No problem in adding more private methods (normalisation).
Strictly forbidden to add more public methods without prior discussion or
consideration during class design.
TDD is where all starts but documentation should be written during
development.
In a PR if documentation doesn't explain the architecture and usability
gets rejected.
Coding with the mind in future developers that will be on board.
New developers should have no problems in understanding the architecture
and design patterns in place.
Maintainable code as the first concern.
I've seen enough spaghetti code in my life.

If you can't right the tests and document them then you don't know what are
you coding for. That is an assumption but my rule.

Plenty of more thoughts about it.
It all comes from experience.

Thanks,

Daniel

Hi Robert,

I find it interesting how many elaborate ordering schemes for methods
seem to be around. I usually only have a block of public methods at
the top and private methods at the bottom. Other than that I don't
employ a particular scheme. Put differently: the need for such a
scheme could be an indication that classes have too many methods on
average. :slight_smile:

When we start to implement a public method and extend the class with it then
we need to go down and right the private method.

It is time consuming.
Also it is harder to refactor.

If you have public and private method together you pick them up and create
the new class without any problem. Just by delegating the public method into
the new class object.

I am not sure I understood you here. Are you talking about copying a
set of methods to another class? Or are you talking about later
creating a new public method in an existing class? Or is this about
refactoring a class and moving code out to another class?

There are other things I can point out as advantages.

Now you made me curious. :slight_smile:

Cheers

robert

ยทยทยท

On Fri, Jan 13, 2017 at 6:24 PM, Daniel Ferreira <subtileos@gmail.com> wrote:

On Fri, 13 Jan 2017 at 17:18, Robert Klemme <shortcutter@googlemail.com> > wrote:

On Fri, Jan 13, 2017 at 4:43 PM, Andy Jones <Andy.Jones@jameshall.co.uk> >> wrote:

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Hi Robert,

> Hi Robert,

>

>>

>> I find it interesting how many elaborate ordering schemes for methods

>> seem to be around. I usually only have a block of public methods at

>> the top and private methods at the bottom. Other than that I don't

>> employ a particular scheme. Put differently: the need for such a

>> scheme could be an indication that classes have too many methods on

>> average. :slight_smile:

> When we start to implement a public method and extend the class with it
then

> we need to go down and right the private method.

>

> It is time consuming.

> Also it is harder to refactor.

>

> If you have public and private method together you pick them up and
create

> the new class without any problem. Just by delegating the public method
into

> the new class object.

I am not sure I understood you here. Are you talking about copying a

set of methods to another class? Or are you talking about later

creating a new public method in an existing class? Or is this about

refactoring a class and moving code out to another class?

> There are other things I can point out as advantages.

Now you made me curious. :slight_smile:

Cheers

robert

--

[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can

- without end}

http://blog.rubybestpractices.com/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>

<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Refactoring a class and copying methods over to another class.

If you like I can try to put in place a simple example but reality it is
almost always more complex.
Those who have experience working in big projects, agile environments,
scrum teams, multiple requirements, tight deadlines may know better what
I'm talking about. Fast delivery is the ultimate goal.

That is why refactoring should part of every sprint iteration. This is true
for Scrum, XP or any other agile methodology.

Hope this helps Robert.

Thanks,

Daniel

ยทยทยท

On Sat, 14 Jan 2017 at 11:58, Robert Klemme <shortcutter@googlemail.com> wrote:

On Fri, Jan 13, 2017 at 6:24 PM, Daniel Ferreira <subtileos@gmail.com> > wrote:
> On Fri, 13 Jan 2017 at 17:18, Robert Klemme <shortcutter@googlemail.com> > > > wrote:
>> On Fri, Jan 13, 2017 at 4:43 PM, Andy Jones <Andy.Jones@jameshall.co.uk > > > > >> wrote:

~~~
Class

Yes, now it makes sense. Thank you! I did not realize the first
sentence was about my suggested approach (split public and private).

Btw. can you do something about your message format and / or quoting?
In GMail I see every other line in your emails as empty.

Kind regards

robert

ยทยทยท

On Sat, Jan 14, 2017 at 1:42 PM, Daniel Ferreira <subtileos@gmail.com> wrote:

On Sat, 14 Jan 2017 at 11:58, Robert Klemme <shortcutter@googlemail.com> > wrote:

I am not sure I understood you here. Are you talking about copying a
set of methods to another class? Or are you talking about later
creating a new public method in an existing class? Or is this about
refactoring a class and moving code out to another class?

Refactoring a class and copying methods over to another class.

Hope this helps Robert.

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Hi Robert,

Is it better like this?

ยทยทยท

On Sat, Jan 14, 2017 at 1:53 PM, Robert Klemme <shortcutter@googlemail.com> wrote:

On Sat, Jan 14, 2017 at 1:42 PM, Daniel Ferreira <subtileos@gmail.com> > wrote:

> On Sat, 14 Jan 2017 at 11:58, Robert Klemme <shortcutter@googlemail.com> > > wrote:

>> I am not sure I understood you here. Are you talking about copying a
>> set of methods to another class? Or are you talking about later
>> creating a new public method in an existing class? Or is this about
>> refactoring a class and moving code out to another class?

> Refactoring a class and copying methods over to another class.

> Hope this helps Robert.

Yes, now it makes sense. Thank you! I did not realize the first
sentence was about my suggested approach (split public and private).

Btw. can you do something about your message format and / or quoting?
In GMail I see every other line in your emails as empty.

Kind regards

robert

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

Hi Daniel,

ยทยทยท

On Sat, Jan 14, 2017 at 3:31 PM, Daniel Ferreira <subtileos@gmail.com> wrote:

Hi Robert,

Is it better like this?

Yes. Thank you!

Cheers

robert

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/