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.
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 🙁