I have seen a fair amount of bad code (some even written by me!) in my 50+ years of software development. This example is a recent favorite. Note this is a snippet of a massive 500k line pile of spaghetti written by one madman.
This is a call to the sub in question. Note that the two values are concatenated to one string with the odd separator of '>'.
$course_year = $course . ' > ' . $year_description;
This is a call to the sub in question. Note that the two values are concatenated to one string with the odd separator of '>'.
$course_year = $course . ' > ' . $year_description;
my $temp = return_data_for_course_year(
$dbh, $course_year, 'all_data');
And here is the opening to the sub. My comments are below.
sub return_data_for_course_year {
my ($dbh, $course_year, $release_status) = @_ ;
if (@temp = split ('\s+\>\s+', $course_year)){
my $cnt = 0;
foreach my $element (@temp) {
$cnt++;
if ($cnt == 1){
$course = $element;
}
if ($cnt == 2){
$year = $element;
}
}
}
- Why were those 2 values combined to 1? Passing 2 args was the solution
- He could have split the string directly into 2 variables.
- He could have extracted the 2 values with simple array indexing and save them in the variables
- The loop and counting is one of the most idiotic things I have ever seen.
Comments
Post a Comment