Information Overload

Unquestionably, a good method name should be descriptive. With today's code completion and code analysis features, almost all developers expect the names to give them at least an idea of what a method should do. When you write a library, or work on a shared codebase, it's a must- and even if one doesn't expect anybody else to use their code, it's still good not to have to remember what stuff doStuff() does.

Some people, however, take it a bit too far. Today's example of abusing good practices was provided by David, who sent the following code with a comment: "This code takes $10 million USD in transactions a month". After reading it, it's fairly obvious the developers shouldn't be trusted with the loose change in their pockets:


class [snip] extends Mage_Sales_Model_Order{

    public function getStatususThatShouldntBeLightlyTrifledWith(){
        return array('paid_fulfilled','paid_unfulfilled');
    }

    public function isAStatusToNotBeLightlyTrifledWith($status){
        return in_array($status,$this->getStatususThatShouldntBeLightlyTrifledWith());
    }

    public function orderIsInAStatusNotToBeTrifledWith(){
        return $this->isAStatusToNotBeLightlyTrifledWith($this->getStatus());
    }

    private function disableHistorySaveCallParentMethoThenReenableHistorySaveThenReturnResultOfCallingParentMethod(){
        $this->internalHistoryDisable = true;
        $backTrace = debug_backtrace()[1];
        $toRet = call_user_func_array(
        array('parent',$backTrace['function']),
            $backTrace['args']
        );
        $this->internalHistoryDisable = false;
        return $toRet;
    }

    public function addStatusHistory(Mage_Sales_Model_Order_Status_History $history){
        return $this->disableHistorySaveCallParentMethoThenReenableHistorySaveThenReturnResultOfCallingParentMethod();
    }

    protected function _setState($state, $status = false, $comment = '',
        $isCustomerNotified = null, $shouldProtectState = false){
        return $this->disableHistorySaveCallParentMethoThenReenableHistorySaveThenReturnResultOfCallingParentMethod();
    }

    public function addStatusHistoryComment($comment, $status = false){
        return $this->disableHistorySaveCallParentMethoThenReenableHistorySaveThenReturnResultOfCallingParentMethod();
    }
 
}

We're not sure what's the biggest WTF here: the ridiculously obtuse method names, the abundance of typos, or the disableHistorySaveCallParentMethoThenReenableHistorySaveThenReturnResultOfCallingParentMethod() function, which walks the backtrace to re-call the function that called it. That last one is certainly an example that sometimes, no matter how hard you try to describe your function, you can still leave your fellow developers completely stumped.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!