How do you order your class methods?

Just getting some layout ideas from other fellow devs.

If you have a class with many methods, how do you try to organize them?
Do you go alphabetical? By related function? Order in which they were
added?

···

--
Posted via http://www.ruby-forum.com/.

If you have a class with many methods, how do you try to organize them?

First, I try to avoid having classes with many methods. I can't
remember having a Ruby class with so many methods that I started to
seriously think about the layout of them.

Do you go alphabetical? By related function? Order in which they were
added?

I usually try to group them according to related functionality. When
I add code later I often only append it at the bottom because that
makes comparing easier.

Cheers

robert

···

On Fri, Aug 10, 2012 at 5:03 PM, masta Blasta <lists@ruby-forum.com> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

If you're using a proper editor to navigate, order won't matter. I always just sort my methods.

···

On Aug 10, 2012, at 08:03 , masta Blasta <lists@ruby-forum.com> wrote:

Just getting some layout ideas from other fellow devs.

If you have a class with many methods, how do you try to organize them?
Do you go alphabetical? By related function? Order in which they were
added?

I generally use a top-down approach, where new methods are added
immediately beneath the method that first requires it. This is most
convenient and can be thought of as a type of logical ordering.

If I was trying to be productive, I definitely would not order methods
alphabetically, especially if the class was large. I'm trying write code,
not rearrange my filing cabinet...

···

On Fri, Aug 10, 2012 at 12:36 PM, Robert Klemme <shortcutter@googlemail.com>wrote:

On Fri, Aug 10, 2012 at 5:03 PM, masta Blasta <lists@ruby-forum.com> > wrote:

> If you have a class with many methods, how do you try to organize them?

First, I try to avoid having classes with many methods. I can't
remember having a Ruby class with so many methods that I started to
seriously think about the layout of them.

> Do you go alphabetical? By related function? Order in which they were
> added?

I usually try to group them according to related functionality. When
I add code later I often only append it at the bottom because that
makes comparing easier.

Cheers

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

How does sorting methods prevent productivity?

···

On Aug 10, 2012, at 09:45 , theadventmaster <theadventmaster@gmail.com> wrote:

If I was trying to be productive, I definitely would not order methods alphabetically, especially if the class was large. I'm trying write code, not rearrange my filing cabinet...

theadventmaster wrote in post #1071970:

I generally use a top-down approach, where new methods are added
immediately beneath the method that first requires it. This is most
convenient and can be thought of as a type of logical ordering.

If I was trying to be productive, I definitely would not order methods
alphabetically, especially if the class was large. I'm trying write
code,
not rearrange my filing cabinet...

On Fri, Aug 10, 2012 at 12:36 PM, Robert Klemme

Alphabetical ordering does makes sense. Since most text editors include
some kind of "fold function" feature, you can fold everything and just
see the method names. If they're alphabetical it is very easy to browse
through them.

If you're using a proper editor to navigate, order won't matter. I
always just sort my methods.

What editor are you using?

···

--
Posted via http://www.ruby-forum.com/\.

You can't have several related methods visible at the screen at the same time?

(Yes, yes, you can use a "proper editor" and see several places in the
file in separate windows. That's like saying that code indentation
doesn't matter because you can use a "proper editor" and reformat
everything.)

-- Matma Rex

···

2012/8/10 Ryan Davis <ryand-ruby@zenspider.com>:

How does sorting methods prevent productivity?

theadventmaster wrote in post #1071970:

I generally use a top-down approach, where new methods are added
immediately beneath the method that first requires it. This is most
convenient and can be thought of as a type of logical ordering.

Thinking about this again: wouldn't it be better to place it below the
_last_ method which requires it? That way one would get topological
sorting and you know that methods called from a method are placed
further down the file which is not the case with your rule.

If I was trying to be productive, I definitely would not order methods
alphabetically, especially if the class was large. I'm trying write
code,
not rearrange my filing cabinet...

Alphabetical ordering does makes sense. Since most text editors include
some kind of "fold function" feature, you can fold everything and just
see the method names. If they're alphabetical it is very easy to browse
through them.

In modern text editors searching is usually quite fast...

Kind regards

robert

···

On Mon, Aug 13, 2012 at 3:54 PM, masta Blasta <lists@ruby-forum.com> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Your argument is flawed.

Code indentation DOES matter, very much so. It is INDENTING code that has been made irrelevant as your editor can (and should) do it for you.

If you use a good editor, you can see several places in the same window, not multiple. You really shouldn't be having to flip back and forth and in this case, tiling (split windows) works better.

···

On Aug 10, 2012, at 15:14 , Bartosz Dziewoński <matma.rex@gmail.com> wrote:

2012/8/10 Ryan Davis <ryand-ruby@zenspider.com>:

How does sorting methods prevent productivity?

You can't have several related methods visible at the screen at the same time?

(Yes, yes, you can use a "proper editor" and see several places in the
file in separate windows. That's like saying that code indentation
doesn't matter because you can use a "proper editor" and reformat
everything.)

Your argument is flawed.

Code indentation DOES matter, very much so. It is INDENTING code that has been made irrelevant as your editor can (and should) do it for you.

No it isn't. What you said only reinforces my point: the way code
looks matters, whether is it indentation or method ordering.

If you use a good editor, you can see several places in the same window, not multiple. You really shouldn't be having to flip back and forth and in this case, tiling (split windows) works better.

Yes, tiling or splitting is what I meant. Of course, there are other
ways to interact with code than with your editor – maybe you're just
reading it on GitHub, or doing code reviews, or looking at a snippet
in documentation.

-- Matma Rex

···

2012/8/11 Ryan Davis <ryand-ruby@zenspider.com>:

I guess if you have an editor with a sorting or method listing feature you
like, you're free to use that.

If you're manually cutting and pasting methods to achieve your desired
ordering, I can't help but wonder if you work in an environment where
deadlines matter, or if you're just programming for kicks.

Generally speaking, I have much better things to worry about during
development than whether or not my methods are sorted to my liking.

···

On Fri, Aug 10, 2012 at 6:33 PM, Ryan Davis <ryand-ruby@zenspider.com>wrote:

On Aug 10, 2012, at 15:14 , Bartosz Dziewoński <matma.rex@gmail.com> > wrote:

> 2012/8/10 Ryan Davis <ryand-ruby@zenspider.com>:
>> How does sorting methods prevent productivity?
>
> You can't have several related methods visible at the screen at the same
time?
>
> (Yes, yes, you can use a "proper editor" and see several places in the
> file in separate windows. That's like saying that code indentation
> doesn't matter because you can use a "proper editor" and reformat
> everything.)

Your argument is flawed.

Code indentation DOES matter, very much so. It is INDENTING code that has
been made irrelevant as your editor can (and should) do it for you.

If you use a good editor, you can see several places in the same window,
not multiple. You really shouldn't be having to flip back and forth and in
this case, tiling (split windows) works better.