Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Legacy code question

by davido (Cardinal)
on May 13, 2019 at 15:20 UTC ( [id://1233705]=note: print w/replies, xml ) Need Help??


in reply to Legacy code question

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

Replies are listed 'Best First'.
Re^2: Legacy code question
by Your Mother (Archbishop) on May 13, 2019 at 16:32 UTC

    While I agree philosophically with you and haukex, I have seen quite a fair bit of code in the wild “written” by users like bigup401. Code that never made sense, was written without use strict, often worked by side-effect or accident or only on a narrow subset of possible input, and is full of no-ops left-over from writing code by cut-and-paste testing.

      "...writing code by cut-and-paste testing."

      To be honest: This was the way i coded my Java stuff the last three years i was in office.

      A funny side-effect of this practice was my my best node ever on PM.

      Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

        Indeed. The more confusing or the worse the documentation for a library is, the more likely I am guilty of the same thing. I endeavor however to both clean it up, attempt to enable the most strict checking, and leave tests behind after I finally understand the situation.

Re^2: Legacy code question
by haukex (Archbishop) on May 13, 2019 at 16:12 UTC

    Very true. I've often seen posts online along the lines of "how on earth did this code ever make sense?", when it seems that a reasonable explanation would be that something simply got overlooked during refactoring.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1233705]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-18 01:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found