|Perl Monk, Perl Meditation|
Re: Do not understand codeby sundialsvc4 (Abbot)
|on Sep 28, 2017 at 19:49 UTC||Need Help??|
Since I am already headed for another dunking in “downvote city,” I thought it might be good to give you two opportunities to do so, as I make further comment about the OP’s particular piece of source code:
unlink $file if /.BGV/;
This statement is about to perform an irrevocable act: it is going to delete a file. The identity of the file that it is about to delete is determined by the preceding source-code which establishes the present value of the variable, $file. But the logic which determines the decision to delete it is not even contained within the statement itself, nor within any statement which obviously surrounds it. The “very(!) pregnant, although at first glance it does not appear so” statement is dependent upon everything which determines the then-present value of a variable, $_, which the Perl language does not even name.
“Your present task is to modify this subroutine.” To do this successfully, you must change the source-code to incorporate the specified new behavior, but without affecting any of its present behaviors upon which any other piece of source code in the entire system might possibly depend ... and you do not have the ability to identify all of those pieces. Nevertheless, you must, along with your change, include tests which demonstrate that your change is correct and that it has no adverse impact. You have about fifteen changes to finish today, all to the same standard.
It should be immediately obvious what a disservice the original programmer did, both to the OP and to his/her project manager.
We must presume that the original code as originally written “worked, at the time,” but that source code is absolutely fragile and non-maintainable. So much so that the OP failed to understand it and was (thank god) able to obtain outside assistance.
Yes, this is how I earn my daily bread today. Hundreds of cases just like this. An uncountable number of source-code examples. And sometimes, a very bitter-tasting announcement to very senior executives: “this software cannot be salvaged.”