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

In reply to On maintaining old code and the battle of styles... by vladb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.