The biggest stench of them all…
July 25th, 2008
Recently here at emak mafu we’ve been building an internal framework to help quickly get some of sites up and running, and have been taking our queues from the Flex framework, asWing and the CS3 components. The best part about this is you get to dive into many peoples code to see their best practices and how they approach the problem (and sometimes shamelessly imitate it). Sometimes you will see a little to-do here, or a quirky comment from a developer as they implement a little hack, but sometimes you begin to get a whiff of a coding smell. This is not to say these frameworks are far in advance of our own, but I’d like to share one whiff that is too pungent to ignore.
The culprit is one mx.controls.listClasses.ListBase, in particular the method collectionChangeHandler(). The first thing to mention is that this class is nearly 10,000 lines long, which is an issue in itself although with the asDoc comments it is easy to forgive this. The method collectionChangeHandler is a method which is 395 lines long, which anyone who has read Refactoring will tell you is suffering from a bad case of long method, which is recommends a method be no longer then 10 - 20 lines.
Now to totally geek out, I started to count the number of if, try.. catch, and for.. loops so I could make a better point of why the method needs refactoring, but after 36th if.. else, 3rd try.. catch and 5th for.. loop I gave up. It is impossible to decipher the functionality without chatting to the author, and in such an important base class as well, where any of this behavior may need to be overriden. Anybody else out there found any blunders?
Leave a Reply