On Method Ordering — Yorai Geffen

Method ordering! Awesome. This has been a topic on my mind, especially since I hate the fact that most refactoring tools place a new method _below_ the caller. For me that is and remains so unintuitive!

What are some strategies:

  • StyleCop says: constructors first, than static, and than everything else
  • Calling (stemming from Clean Code) says: first the calls, then the definition. Like a book they say. Which I disagree with!
  • Connectivity says: methods should be grouped by their functionality
  • Calling + Connectivity: a combination of the former two

What strategies are used in practice?

Yorai analyzed 128,000 Java files, and found that 93% of projects scored at least 0.95 on one of the strategies (95% of the project follows the strategy) Calling is most popular and real world projects seem to abide by an ordering standard, but that might be caused by the fact that most refactoring tools encourage that.

2016-05-16 15.04.55

Sorry for the crappy quality. There was only power in the back of the room.

Are some orders better than others?
The authors made an online questionnaire and created different variants of the class: the original one, a random one, and each of the above styles. They gave participants three different (randomly assigned) code comprehension tasks. Turns out the order does not matter for the correctness, but it does for time. And, it affects beginning programmers more than experts.

Unfortunately no preprint 🙁


  1. Job van der Zwan

    So *how* did it affect them? Don’t leave us hanging like that!

  2. Shahar Maoz

    A copy of the paper and additional materials are available from: http://smlab.cs.tau.ac.il/ordi/

Comments are closed.