Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: Old NumberCrunching Modules

by davido (Archbishop)
on Aug 13, 2012 at 15:58 UTC ( #987143=note: print w/replies, xml ) Need Help??

in reply to Re: Old NumberCrunching Modules
in thread Old NumberCrunching Modules

I can't agree more with the tirade against monolithic functions that span several pages. A few months ago I was working on refactoring some code where many functions reached or exceeded around 200 lines. And as I began refactoring it was amazing how many places I found that I could generalize what five to fifteen lines were doing in a way that could be reused across several of those functions. The end result was fewer total lines, no functions beyond a single page, and in my opinion, easier to read and maintain (which was my motivation behind refactoring it -- I needed to maintain it and found it to be unmanageable without this sort of sprucing up).

My inspiration was derived from Schwern's Skimmable Code talk (PDF... sorry). I wanted to follow-up to your post to get that link out in the open once again; it's a great resource.


Replies are listed 'Best First'.
Re^3: Old NumberCrunching Modules
by Tux (Abbot) on Aug 13, 2012 at 16:29 UTC

    But refactoring for the sake of refactoring - or just to get a shorter method/function body can easily led to just the oposite, as I have sadly seen way too often.

    A perfectly sane 400 line function/method stuffed with comment of a process that was a sequential series of logical steps that only got interrupted by serious Exceptions/dies was broken into several parts shattered across modules without proper call-checks and, worse, rewritten in an understanding that was not true, thereby killing the whole process.

    Some people say they understand code better when it is rewritten into smaller chunks. That might (very) well be true if any of those chunks is to be reused or makes a perfectly sane unit. If the code however is not (ever) to be shared or reused by other parts, refactoring just because of size most of the times leads to serious errors. At least in my experience.


    Enjoy, Have FUN! H.Merijn

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://987143]
[shmem]: just one proverb before dozing off: when dealing with a bear, hubris is suicidal
[shmem]: Old_Gray_Bear would nod, and go back to sleep, then - but he's been sleeping for a year now.
[erix]: "AngloZionist Empire"? "Stop the Empire's war on Russia?" WTF?
erix stops reading as recommended by the blog itself
[erix]: my attention being jealously guarded ;)
[shmem]: erix, yes, it's a WTF. Since...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2018-03-19 20:49 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (246 votes). Check out past polls.