Article 6YTR CodeSOD: Descriptive Overload

CodeSOD: Descriptive Overload

by
Maciej Stachowski
from The Daily WTF on (#6YTR)

256px-Information_Overload.jpg

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.

inedo50.png[Advertisement] Use NuGet or npm? Check out ProGet, the easy-to-use package repository that lets you host and manage your own personal or enterprise-wide NuGet feeds and npm repositories. It's got an impressively-featured free edition, too! TheDailyWtf?d=yIl2AUoC8zAXMRGb1S4jc0
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments