It's been some time now that I've taken upon coding on an application that someone else's built. Now that's not unusual, I have done so on many other projects. What makes this endevour quite unlike many others is that it has made me realize how often we can find bad code. Sorry, scratch that, I mean really bad code.
It's not bad code as a result of ignorance, but worst, because of bad habit. Actually, scratch that too. I would say malice. Take this PHP class:
PHP:
| class SomeClass { |
| function someFunction($parameter = null) { |
| |
| if ($parameter == 1) { |
| |
| return $this->__launchA($parameter); |
| } else { |
| |
| $this->error = 'Not good'; |
| } |
| |
| |
| $value = $this->__launchDefault($parameter); |
| |
| |
| if ($value > 2) { |
| return $value; |
| } |
| |
| |
| return false; |
| } |
| |
| function __launchA($parameter = null) { |
| |
| switch($parameter) { |
| |
| case 2: |
| return 2; |
| default: |
| return $this->__launchDefault($parameter); |
| |
| } |
| } |
| |
| |
| } |
Because of some NDA agreement that I have signed, I'm actually mocking what I have to deal with every day. But trust me, it's much worst than this. Get the picture? A huge chain of private methods, calling each other, and a comment ratio *way* about what is acceptable (what good is it if on a comment you are actually explaining what a very simple if statement is doing?). Now, you may be asking yourself, why do I call this (crappy) code malice? Because it is meant to generate mode source code lines. Therefore: more money to charge to the client.
I have seen this over and over lately, on a very big project I'm working on. And the truth is, as a member of an outsourcing software developing firm, I've come to realize that us (freelance developers) should be accountable for such bad code. The one who produced this kind of crappy code should be made accountable for the amount of hours it takes to refactor their code, and make it actually usable.