Mar082008

Real life lessons: take your code and shove it!

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:

class SomeClass {
	function someFunction($parameter = null) {
		// If the parameter is 1
		if ($parameter == 1) {
			// Launch a passing parameter
			return $this->__launchA($parameter);
		} else {
			// Give back error
			$this->error = 'Not good';
		}

		// Launch the default function sending parameter
		$value = $this->__launchDefault($parameter);

		// If value returned is ok, give it back
		if ($value > 2) {
			return $value;
		}

		// If not valid, return false
		return false;
	}

	function __launchA($parameter = null) {
		// Take action based on $parameter
		switch($parameter) {
			// If it's 2
			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.

No related posts.



Leave a Comment

2 Comments to "Real life lessons: take your code and shove it!"

  1. Mar082008 at 10:19 pm

    Jason Leveille [Visitor] wrote:

    As I don’t have much experience with freelance work (I work for a fantastic software development company), perhaps I’m unfamiliar with the practice of charging more based on the amount of source code. Even as a freelancer you must develop a project scope prior to committing to a project. So, strictly speaking, I’m assuming you are translating more lines of code to more man hours for the freelancer, therefore more money. Is that the case?

  2. Mar132008 at 9:16 am

    David Garcia Watkins [Visitor] wrote:

    Believe me, I know perfectly what you are talking about because I have been in that situation a couple of times.

    But in my experience, sometimes it happens due to standards that aren’t deeply understood.

    For example, I once worked with the following rule: “if a function has more than 10 lines, something is wrong and you need to split it.”

    This could be good rule (with exceptions) if you understand its purpose, but if you blindly follow it you can easily end up with the above code.

    Good day!

 
Powered by Wordpress and MySQL. Clauz's design for by Cricava