Some of the Dumbest Code

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; 
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; } } }

  1. Why were those 2 values combined to 1? Passing 2 args was the solution
  2. He could have split the string directly into 2 variables.
  3. He could have extracted the 2 values with simple array indexing and save them in the variables
  4. The loop and counting is one of the most idiotic things I have ever seen.

Comments