Re: Re: Function size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Just want to throw my 2 cent in :)

2012/5/30 Tony Marston <tony@xxxxxxxxxxxxxxxxxxxxxxxx>

>
> "Ashley Sheridan" <ash@xxxxxxxxxxxxxxxxxxxx> wrote in message
> news:1338326229.2616.31.camel@localhost.localdomain...
> > On Tue, 2012-05-29 at 17:06 -0400, Paul M Foster wrote:
> >
> >> On Tue, May 29, 2012 at 08:52:46AM +0100, Tony Marston wrote:
> >>
> >> > On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote:
> >> > >  A rule of thumb is no more than 50 lines per
> >> > > function, most much less. Back in the day when we didn't have nifty
> >> > > gui screens and an 24 line terminals (yay green on black!), if a
> >> > > function exceeded one printed page, it was deemed too long and
> marked
> >> > > for refactoring.
> >> >
> >> > I think the idea of setting an arbitrary limit on the number of lines
> >> > that a
> >> > function should contain is quite ludicrous and something which I will
> >> > completely ignore. If a function requires a hundred or more lines then
> >> > so be
> >> > it. The only reason to take a block of code and put it into its own
> >> > function
> >> > is when that code is likely to be called more than once so that it
> >> > conforms
> >> > to the DRY principle. If it is only ever used in one place then there
> >> > is no
> >> > point.
> >> >
> >> > The problems I have with creating lots of small used-only-once
> >> > functions is
> >> > as follows:
> >> > - you have to create a meaningful name for each function.
> >> > - all those functions should be arranged in alphabetical order within
> >> > their
> >> > containing file - having them in a random sequence makes it difficult
> >> > to
> >> > find the one you want.
> >>
> <snip>
> >
> > And yeah, alphabetical order? Really?
>
> This is a throwback to my 3GL days when all components within a file were
> arranged in alphabetical sequence so that they were easier to find when you
> looked at the printed listing.
>
> > Group them by similarity, sure.
> > But today, with IDEs that will jump straight to functions and class
> > methods, and the good ol' find tool on every editor I've ever seen, is
> > sorting them alphabetically really necessary? Seems like a waste of time
> > that is likely not going to be done by fellow developers working on the
> > same codebase.
>
> I have never come across an IDE that jumps to a function when you click on
> its name, so how does it return to where you jumped from?
>

At least PhpStorm and Eclipse have a feature to return where you come from.
I haven't seen an IDE, that is _not_ able to jump to a functions or methods
source for a long time now.


>
> Rather than artificially reduce the size of a function to satisfy someone
> else's limited attention span I would rather use the scroll wheel on my
> mouse. Scrolling up or down within a single function is easier than
> searching/finding/jumping to a series of sub-functions which may exist at
> random locations within the same file.
>

If the functions were named properly you don't have to follow every
execution path to the deepest deep. Or do you reading PHPs C-source, just
because a wild "substr()" appeared? When you see a method "loadFromFile()"
and the IDE tells you, that it expects a $filename as parameter, why should
you jump there just to make sure, that the method loads something from a
file by the filename given as first parameter?


>
> I will only split a large function into sub-functions when it makes sense
> to
> do so, and not because some nerd cannot scan more than 20 lines at a time.
>

The question I ask myself is: Why ^should^ a scan more than 20 lines at a
time, if it is possible, to make it clearer, but another nerd decided, that
it is too much work (or whatever). Maybe it's may "attention span", but I'm
usually slightly bugged, when I have to read code monsters. Compared to a
book it's a kind of "One chapter in a single sentence".


Regards,
Sebastian



>
> --
> Tony Marston
>
> http://www.tonymarston.net
> http://www.radicore.org
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux