Re: Rehabilitating bad Perl code

Discussion in 'Perl Misc' started by ccc31807, Jan 9, 2013.

  1. ccc31807

    ccc31807 Guest

    On Tuesday, January 8, 2013 2:37:57 PM UTC-5, Henry Law wrote:
    > I have inherited some code which has uses several horrible constructs, >
    > such as splicing together completely unrelated assignments and >
    > statements with commas, like
    >
    > inches thick of this stuff. Does anyone have any experience I could >
    > draw on?


    Indeed! I inherited several inches of Perl code (literally, the author diedvery suddenly) that two of us spent several weeks reading - to little avail.

    My partner took another position, and I rewrote the whole damn thing (and yes, the profanity is justified.)

    Benefits:
    1. We rewrote the network part in Java, which as it turned out a wise decision as the applications we interfaced with were Java and we benefited from the available classes.
    2. We modularized the code, my first big experience in reducing a large code base to modules, which has benefited me since.
    3. I intentionally attempted to rewrite the code in a functional style, which has paid for itself in decreased maintenance time over the years.
    4. Since I wrote the code, I know it inside out, which I would not have learned nearly as well simply by reading code someone else has written.
    5. Having a negative example, I tried my best to use best practices, which taught me some good lessons.

    My approach at least in the beginning was to write functions which acceptedparameters and returned results using lexical variables as much as possible, and commented out the existing code. Often this exposed global variables, some of these literally a couple of KLOC away from the use of the global.Getting a handle on the globals really allowed me to increase the pace of my rewriting effort.

    My best advice is not to look on this as a negative, but as a positive. Youwill be much better off seeing this as an opportunity to do good rather than as a burden to carry.

    CC.
    ccc31807, Jan 9, 2013
    #1
    1. Advertising

  2. ccc31807

    David Combs Guest

    In article <>,
    ccc31807 <> wrote:
    >On Tuesday, January 8, 2013 2:37:57 PM UTC-5, Henry Law wrote:


    >3. I intentionally attempted to rewrite the code in a functional style, which has paid for itself in decreased maintenance time over the years.


    [very late followup, this]

    For education of us all, please say a bit about how you
    wrote perl code in a functional style.

    Not a whole tutorial, but maybe a few short examples,
    maybe even before-and-after versions?

    THANK YOU!

    David
    David Combs, Feb 28, 2013
    #2
    1. Advertising

  3. (David Combs) writes:
    > In article <>,
    > ccc31807 <> wrote:
    >>On Tuesday, January 8, 2013 2:37:57 PM UTC-5, Henry Law wrote:

    >
    >>3. I intentionally attempted to rewrite the code in a functional style, which has paid for itself in decreased maintenance time over the years.

    >
    > [very late followup, this]
    >
    > For education of us all, please say a bit about how you
    > wrote perl code in a functional style.


    Judgeing from the text, I think what he meant is structuring the code
    into named subroutines solving subproblems instead of the usual "5000
    lines down the road, there comes the final bracket of 'the loop'" (cf
    "Real programmers don't use Pascal").
    Rainer Weikusat, Feb 28, 2013
    #3
  4. ccc31807

    ccc31807 Guest

    On Wednesday, February 27, 2013 9:19:34 PM UTC-5, David Combs wrote:

    > >3. I intentionally attempted to rewrite the code in a functional style, which has paid for itself in decreased maintenance time over the years.

    >
    > [very late followup, this]
    >
    > For education of us all, please say a bit about how you
    > wrote perl code in a functional style.


    I should have said 'procedural style', by which I mean named blocks of code that accept arguments and return results.

    I would recommend 'Higher Order Perl' which is available as a free web version, but by the book to encourage the order. This is a good book. You probably won't write Perl in a (true) functional style, but the techniques are slick.

    CC
    ccc31807, Mar 1, 2013
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    849
  2. Eric Anderson

    Bad Transform or Bad Engine?

    Eric Anderson, Oct 4, 2005, in forum: XML
    Replies:
    1
    Views:
    363
    Peter Flynn
    Oct 5, 2005
  3. Gene

    Re: Bad code or bad compiler?

    Gene, Jun 1, 2008, in forum: C Programming
    Replies:
    3
    Views:
    271
    Barry Schwarz
    Jun 1, 2008
  4. Willem

    Re: Bad code or bad compiler?

    Willem, Jun 1, 2008, in forum: C Programming
    Replies:
    9
    Views:
    270
    Keith Thompson
    Jun 2, 2008
  5. rantingrick
    Replies:
    44
    Views:
    1,165
    Peter Pearson
    Jul 13, 2010
Loading...

Share This Page