Aug 26, 2011

Eclipse Clean Code Method Sorter: Try #1


A few months ago, a colleague and I had a hot discussion on good styles of sorting methods in source code, and (of course) we also discussed the advantages of the newspaper-style as proposed by Robert C. Martin:
Have you ever chased your tail through a class, hopping from one function to the next, scrolling up and down the source file, trying to divine how the functions relate and operate, only to get lost in a rat’s nest of confusion? Have you ever hunted up the chain of inheritance for the definition of a variable or function? This is frustrating because you are trying to understand what the system does, but you are spending your time and mental energy on trying to locate and remember where the pieces are.
Concepts that are closely related should be kept vertically close to each other. We want to avoid forcing our readers to hop around through our source files and classes.


Robert C. Martin "Clean Code" pp. 80

Unfortunately, Eclipse doesn't support sorting members in "clean-code style". Thus, we decided to give away this idea to a pair of students as an Eclipse hand's-on training. This post is a follow-up of my post in May.

To get you started, here is a quick refresh of the problem:

Typically, there are two types of code ordering. Alphabetically (+ modifiers) or completely hand-crafted (which in many cases means "without any particular order"). But is it that complicated to let the IDE sort a class' members for you? Reducing the need to hop from top to the bottom of the file and thus minimizing scrolling and confusion?

The slide below gives you an example of how a well-sorted piece of code might look like. As you see the number of hops required to read the whole code is minimal since there is a clear ordering between the code:



How complicated can it be?
It's amazingly complex :) We had to learn that an optimal solution would be APX-hard to find (did you no that complexity class before? I didn't.) Anyways, we had quite tough discussions with our students and sometimes even bar room fights what might be the best solution. To make that part of the story short,  Mateusz and Fabian came up with two solutions. One solution is already available for testing.

If you like the newspaper-style as described by Robert C. Martin, you should give it a try! Please check this wiki page for further information about the plug-in and installation instructions (it's not an official part of Code Recommenders yet).


To track the progress of this feature, add yourself to this bugzilla report.


Best,
Marcel



Stay in touch with Code Recommenders via Twitter.