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

Re: Finding duplicated code in Perl

by TomDLux (Vicar)
on Nov 27, 2003 at 01:01 UTC ( [id://310437]=note: print w/replies, xml ) Need Help??


in reply to Finding duplicated code in Perl

The code uses system to sleep 2 or 5 seconds. Is it waiting for something to happen? Giving some code a chance to complete?

It uses a shell method to copy files and perform other system commands. Are these complicated? on a remote platform? Or simply not built-ins in the original language?

I had a similar problem last winter, miles and miles of bad linear code, though in my case the problem was the original codeers, rather than the original language. I keep thinking about writing an article like the ones MJD has, how 3000 lines of bad code can collapse into 137 lines of good code.

Begin by reading a few files, getting the feel for what they do. Take one file, edit to reduce repetition, using conditions, loops, etc. Rename poorly named variables, to increase clarity. Refactor code into routines: Top level code shoudl consist of built-in commands, object constrruction, and subroutine calls. Subroutines that actually do the work should be short, a dozen lines, two dozen at the most, and should do one thing. Those routines are used in more complicated routines. This way, it will be easier to share subroutines between files. Don't worry about making one file perfect. Just simplify it and go on to the next; you'll be back to share code, anyway.

--
TTTATCGGTCGTTATATAGATGTTTGCA

Replies are listed 'Best First'.
Re: Re: Finding duplicated code in Perl
by shushu (Scribe) on Nov 27, 2003 at 19:28 UTC
    Hi all,
    Thanks for the interest in the problem and in the language.

    First, regarding to CPD tokenizer requirement - looking inside CPD sources I see they need the yokenized data in java structure. heir own PHP and C++ tokenizers are written in Java, but it doe snot mean we cannot execute Perl tokenizer, and they import the data (though it will take time to fit the information, I guess).

    Meanwhile I executed CPD over some C code and got very nice results. When changing my Perl files into .java I got some limited answers as well, so I might just use what I got. It depends whether I will get the reources (tiem and people) to work on it or not.

    Regarding to the language, and the primary language -
  • It is called QTL, and it comes for Qa Testing Language
  • Using this language we were able to execute distributed tests over any number of machines in a multi platform environment. All, BTW, written in Perl.
  • The new version, already working for a year, reduced the amount of special QTL commands, and gave the developer (almost) full Perl capabiliites.
  • Two main objects are use in QTL/Perl - a machine, and a label
  • $machine->command() will execute the command on the remote machine, and will return a $label.
  • $label->attribute (such as result, state, exitcode) will check the executed command and give the developer updated status all of the time
  • The converter from the old language to the new syntax was rather simple, and was executed a year ago. This means we cannot go back to the old sources, since we had many changes already.


  • I cannot give more information without management approval (which I won't get, I believe) - this is not an open source project. On the other hand, I plan to give a lecture in YAPC::Israel::2004 which will take place on February 2004, so you are all welcome.

    Back to our business - the duplication detector - although it is very interesting stuff, unless I come up with a fully automatic tool that find duplications over several files and give the user proper information on what to do with them, I believe I will need to take some of your advices, and work manually on it.

    Question is - what do you think will take longer, and what do you think will be more reliable ?

    Thanks,
    shushu

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://310437]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-19 20:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found