The code is using an array to hold a single element at this particular line. Later in the code it is possible that an array is desirable for some other reason; something gets added, or a subroutine called with a funky prototype, or it is otherwise convenient.

Often when examining legacy code you'll find artifacts of the past. Perhaps an array is not all that useful at this point in the code as it exists today, but maybe seven years ago an array was exactly what was needed. Things that needed to change got changed, and things that continued to work didn't get changed.

Or it's just dumb. That's usually the last explanation to assume, though. More often than not either it is this way for a reason now, or is this way because of the code's evolution over time. But dumb is a perfectly reasonable explanation too, and not necessarily an indictment on the developer. I find myself having to forgive myself sometimes, too. The best explanation I have is that I must have been focusing on some other aspect of the problem and didn't notice I had left an inelegant construct laying around as I iterated through the process of crafting a solution.


Dave


In reply to Re: Legacy code question by davido
in thread Legacy code question by Zenzizenzizenzic

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.