Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Re: Rehabilitating bad Perl code

Reply
Thread Tools

Re: Rehabilitating bad Perl code

 
 
ccc31807
Guest
Posts: n/a
 
      01-09-2013
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.
 
Reply With Quote
 
 
 
 
David Combs
Guest
Posts: n/a
 
      02-28-2013
In article <(E-Mail Removed)>,
ccc31807 <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
 
Rainer Weikusat
Guest
Posts: n/a
 
      02-28-2013
http://www.velocityreviews.com/forums/(E-Mail Removed) (David Combs) writes:
> In article <(E-Mail Removed)>,
> ccc31807 <(E-Mail Removed)> 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").
 
Reply With Quote
 
ccc31807
Guest
Posts: n/a
 
      03-01-2013
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
integer >= 1 == True and integer.0 == False is bad, bad, bad!!! rantingrick Python 44 07-13-2010 06:33 PM
Bad media, bad files or bad Nero? John Computer Information 23 01-08-2008 09:17 PM
ActiveX apologetic Larry Seltzer... "Sun paid for malicious ActiveX code, and Firefox is bad, bad bad baad. please use ActiveX, it's secure and nice!" (ok, the last part is irony on my part) fernando.cassia@gmail.com Java 0 04-16-2005 10:05 PM
24 Season 3 Bad Bad Bad (Spoiler) nospam@nospam.com DVD Video 12 02-23-2005 03:28 AM
24 Season 3 Bad Bad Bad (Spoiler) nospam@nospam.com DVD Video 0 02-19-2005 01:10 AM



Advertisments