views:

226

answers:

5

hi there,

My company develop web apps using combination of mod_perl, axkit and apache. We have tons of Perl modules, javascripts, etc, all in unix operating system.

Whenever I need to write a new function, I try to do some code reuse, but the thing is all the Perl modules and javascripts are scattered across folders.

i hate to write some code only later to discover that there's already a function which done the same thing, my current method involves trying to grep for the table name to see if there's a redundant function, but besides that, i'm pretty much will just give up and write a new function because i don't want to spend too much time searching and finding nothing.

Is there a better way to do this? Or even better, are there freeware tools that I can install which can help me properly manage all the functions and modules, and even allow developers to log comments, etc.

EDIT

There is this discussion on detecting code duplication on c++ using tools, do we have anything like this for perl codes in unix platform?

thanks ~steve

+1  A: 

I trust you have some form of version control software (svn, Mercurial, git, whatever but not VSS)? If you don't now is time to get one and start using it. That way, you have at least an idea of which modules you are using and where the code is. You can also use a ctags-like to index all the modules you have written (or are using).

An IDE (as much as I dislike these) can also help finding code and refactor.

Keltia
well basically we are using cvs in unix, but it still not an efficient way enough for me to go through all functions to avoid rewriting code. and there's plenty of modules which is already there and untouch to my horror. do u have ide in unix? i use vi currently.
melaos
CVS is far from being perfect but one VCS is better than none. We managed to work on FreeBSD for more than 10 years with it. Index your code with ctags like I said to know what you have. On UNIX, you can use Eclipse or Netbeans as IDE.
Keltia
hi can you provide more information on how to start on the VCS setup? thanks.
melaos
You already have the code in *a* VCS namely CVS so the first step is already done. Try to find something to index your code with and check your CVS logs to find out exactly what's in there.
Keltia
+6  A: 

Organize your source directory so that each functionality has only one place where it should be and it's easy to find something.

Make sure to share naming convention to prevent duplication.

Design your module so that they do one thing only - and do it well.

Review the code to make sure names and locations are correct.

Provide a efficient search engine based on a code indexer so that it's easy to look if there is already a function doing a peculiar task.

Don't underestimate the time to generalize an existing component so that it can effectively be reused.

Document the modules, with API documentation an/or unit-tests.

Communicate within the Team so that every one has a good grasp of what has possibly been already written, who has or knows who may have working on/used a module.

philippe
can you provide more details on the search engine? the thing is there's currently only me and my team lead, and a stack of old codes. and this not really much of a company project but more on an initiative on my part to avoid redundant codes..
melaos
The idea is to be able to search for any piece of code based on keywords (e.g. look for calendar, date, week). For a team of 2, an indexer such as OpenGrok (http://en.wikipedia.org/wiki/OpenGrok) - can be overkill, ack could be enough (http://petdance.com/ack/)
philippe
ok, as long it's simple so i can start small and start to propagate this to my team lead and other future developers in my company.
melaos
ack! is just an improved grep, and it's a single file Perl script. Cannot be simpler.
philippe
awesome, thanks dude, i'll check it out pronto.
melaos
A: 

I've once worked in a company that used Perl, and have similar problems. The solution we come up with, was to reorganize the functions in files, taking in consideration a 3-tier architecture (presentation, business and persistence), and the elements being manipulated.

So, we have one perl file to each main table in database, one perl file for each entity to manipulate their business operations, and so on ... with this, it's easy to avoid code duplication, because you know exactly where to look for a given function.

Alexandre
A: 

This is something I am very interested in.

Using a simple version control software like svn, git or bazaar is not exactly what I want. A VCS is mandatory in addition to such a system, but it is not this system. After some research, I have been told to look into packaging in order to achieve this, and I think, some sort of packaging system is the way to go.

If you want an example of packaging systems, look at debians APT. Each package has dependencies with versions a description and sourcecode and given a good packaging system, you can go like "magic search set equation fixpoint", and the magic packaging system is going to find a module that solves the problem. If you include the package in your source code, it would also add all missing dependencies like probably a graph and such.

However, the research into this started shortly before my laptop's hdd died, which deferred further research and actual results into this direction, but maybe you are able to find something interesting (and tell me nudge, nudge)

HTH, Tetha

Tetha
hehe, well all i know is here in this thread.
melaos
A: 

If your modules include POD documentation and are installed under a common directory or set of directories, it should be relatively easy to use pod2html to generate HTML documents. Once you have the HTML documentation, throw in a Full Text Search index (SQLite with fts3, MySQL, Lucene, KinoSearch, whatever) and a simple search form app (CGI or mod_perl) and you're ready to go.

If you're using trac, there's a plugin that will create trac wiki pages pages from your .pod and .pm files, again, making your documentation easy to search.

converter42