Maintaining someone else's code is a laborious and tedious task.
I believe that most of the monastery monks here had to go through
a similar experience either at work or in the open source community.
The job of adding or extracting anything from existing system/module
is made even harder by a combination of either of these: poor
documentation, inadequate design, or simply conflicting coding style.
For the purpose of this post, I'd like to focus on the coding style
conflicts. Just recently I happened to help out with a few enhancements
to a Perl module (on cpan). The module didn't have glaring design
flaws or anything of such nature. Yet, I found my coding style and taste
conflicting with that of the original author of the module (no longer
maintaining it).
For example, my preferred way of passing arguments to a sub is using a
single hash parameter instead of a lengthy list of arguments (this
crosses over with the
passing arguments node). Just like here:
sub _update_term_score {
my ($self, %args) = @_;
# %args = (
# term => search term
# doc_id => document id
# count => number of times term was found in this document.
# )
. . .
}
instead of,
sub _update_term_score {
my ($self, $term, $doc_id, $count) = @_;
# term -> search term
# doc_id -> document id
# count -> number of times term was found in this document
+.
. . .
}
Further, there are subtle conflicts such as not using single quotes for
hash key values (that's what I prefer):
my %hash_var = (
param1 => 'value 1',
param2 => 'value 2',
param3 => 'value 3',
);
instead of,
my %hash_var = (
'param1' => 'value 1',
'param2' => 'value 2',
'param3' => 'value 3',
);
To continue, I'd have to write an extra 2 pages of similar rant and plea for you to
read to the end (unlikely eh? :). Therefore, on I go to the actual conclusion and
key question...
What really bothers me in all this is realizing that anyone coming to maintain this module
after me will have to deal with both _my_ code and that of the original author. Mind me,
there's nothing inherently wrong with either styles, it's all in taste and the attitude.
So, would it be more considerate of me to simply follow the initial lead and try to stick
to the existing code style as much as possible? Besides, if I were to look at a code
with two or three or ... (you get the idea ;) conflicting styles, I'd assume (probably wrongly)
that the code was designed poorly or that the author(s) were not competent in what they did...
besides that's what every book on good Software Engineering would tell you.
"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith
|