Learn to write code for my sanity

I'm currently at work, and I seriously needed a break, which is why I'm here, writing something for my blog. Why? It's a long story, but I'll keep it short.

My boss decided to start using part of our program that hasn't been modified since 2004, and last used in early 2005. Of course, with all the changes we've done, lots of bugs started cropping up, so he put that on my lap. The problem is, I didn't make this part of the program. Someone else who worked here until early 2005 worked completely on that module. Now that person is long gone, and I'm stuck with his code.

"No biggie", I thought. "This shouldn't be too difficult to modify for what the boss wants now." Then I opened the file... It was a total mess.

I mean, I had seen messy code, a lot from myself. But this was messy. And if I have to bold and italicize a word, it's because I really mean it. This was the worst code I have ever seen written by any developer ever. I know that PHP has a reputation for producing some awful code, but this really took the cake.

We start off with lots of Dreamweaver generated code at the beginning (some Javascript code that apparently doesn't do anything in the application). Then we head off towards the land of unknown variables: $dbQuery1, $dbQuery2, $dbQuery3, and my personal fave, $c. Also, there was virtually no indentation all around, and the indentation that did exist was very poorly done (some if-else blocks were completely on the left margin of the code). Add up that there were exactly two comments consisting of only one word throughout the 600 lines of code, and you have a developer with a huge headache, trying to figure out what the damn thing does. And while it kinda works, now I'm faced with the dilemma of trying to add new functionality to the module while not breaking anything.

The worst part of it all is that I showed the code to one of the technicians here who actually studied in the same web-development class as the previous developer, and he told me "That's how he's always programmed." So I asked what the teacher did with that code, and he told me "The teacher probably writes worse code than that." What? A college professor writing worse code than that?

I can't believe that Computer Science professors aren't enforcing their students to learn how to write clean and maintainable code. And I don't think this is an isolated incident, because at my university, the professors didn't enforce this either. And while we were taught to use indentation correctly, informative variable names and all that, they never said anything if we didn't follow those simple steps.

If I were a college professor giving a programming class, I would enforce those rules, probably almost harshly. If I see generic variable names (like the ones I mentioned above), I'll dock one or two points from the final grade. If indentation isn't used correctly, another one or two points disappear. And if the code is as unreadable as the code I'm working on now, I'll probably fail the student, or at least give him one more day to fix that code before giving it back to me.

I'm curious to know if anyone else has seen this at college, or if it's just another Puerto Rican incident.