Other Peoples' Code

jonasbn on 2002-12-19T21:40:11

Well I was so lucky to get a task of adding some functionality to a Perl script which had been developed by a consultant. I know I have written about this before (actually on the 11th. of october).

This time strict was enabled though - anyway I started with adding a -w to the she-bang line, warnings started to show up.

The developer seem to have been working with Perl 4, so I started to refactor the script to a more Perl 5-ish style (well just the perlstyle actually). After this I started refactoring seriously on the code, moving subs into a module, adding tests and eliminating overly use of the same strings and different variable for holding the same kinds of data ($mode and $status).

At the same time I started adding the new functionality, and all of a sudden I lost track, what was I doing... it was still compiling, but I was loosing focus.

Things where getting messy (I know this is not the purpose of refactoring), I had all of a sudden ruined quite a few of the APIs of the different subs. So I thought to myself, how can I ensure that I don't break everything - well in VB.NET all subs have signatures and ... hey thats it - Perl's prototypes

So I started looking into the Perl prototypes, I then added prototypes to all the subs and now when I compiled I was told when I had ruined some interface to a sub - phantastic.

Again I located something new (to me) in Perl and have learned something new. Now I know a little about prototypes in Perl and I have developed myself a new refactoring technique.

Out of chaos came order, and as I often have said before: learning another language gives perspective to your primary language (heh - I am no Mark Jason-Dominus).