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.


Stay in touch with Code Recommenders via Twitter.


  1. Isn't it a plain topological sort? Did I miss something?

  2. If you assume alphabetical order for nodes with no fan-in, and doing a depth-first traversal of the call relations: yes, that's easy :)

    It get's more complicated if you would like to minimize the *total* number of jumps to make (maybe by relaxing the exact news-paper style), if you try to put getters close to their setters and several other features :) Can you imagine other criteria name alphabetic and call-relations?

  3. I like this, but I do have a couple of issues.

    I would like to see getters and setters completely excluded from the invocation ordering strategy. I want the getters and setters to appear last in the class, alphabetically ordered - but considered as outcasts compared to the more important methods!

    As I am coding, I have the occasional public method that isn't invoked within the same class - these are ordered alphabetically within the lowly getters and setters too.

    The functionality is only exposed through right click on an editor > Source. It doesn't appear on the Alt+Shift+S shortcut, or on the source menu.

    Whoever worked on this should be very proud of themselves!

  4. Did this awesome project die already? I just noticed that awkward custom of mine to arrange methods topologically by their call order when I had to debug an awfully large class of 2k+ lines recently and had to jump through the code quite a lot. Now I started googling with that idea in my mind: Why not check if there is some tool that would allow me to
    1) order most method calls topologically (as Robert said, the "more important" methods)
    2) Getters/setters below, alphabetically or according to the order of the member declarations (public getXXX/setXXXX)
    3) event handler methods (public onXXXX)

    And now I see there appear to be no more updates on this genuine project? What a pity! If this is true, is this project open source so that it could be extended by other developers?

    Michael Jess

  5. Hi Michael,

    this project was developed by a student during a hands-on but not continued after the final submission. The code should be somewhere around. If you are interested to continue working on it or you know a student that might work on it as part of this year's Google Summer of Code, I can see whether I can get the code.

  6. Extremely intriguing online journal. A lot of web journals I see nowadays don't generally give anything that I'm keen on, however I'm most definitely inspired by this one. Recently felt that I would post and let you know.


  7. brillant piece of information, I had come to know about your web-page from my friend hardkik, chennai,i have read atleast 9 posts of yours by now, and let me tell you, your webpage gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanx a million once again


  8. Quality articles is the secret to attract
    the visitors to go to see the site, that’s what this website is providing.


  9. 먹튀검증 whoah this blog is wonderful i really like studying your
    posts. Stay up the great work! You realize, lots of individuals are searching around for this information, you can aid them greatly.

  10. Great Information sharing .. I am very happy to read this article .. thanks for giving us go through info. 온라인카지노

  11. This is very interesting! Great information and it is also very well written. I will bookmark and comeback soon 메이저검증

  12. This information is invaluable. How can I find out more? 사설토토

  13. Quality posts is the key to be a focus for the visitors to visit the web page, that’s what this website is providing. 파워볼게임

  14. Thaks for sharing wonderful article.. keep on the post thank you.Divorcio rapido no disputado en Virginia