The Order of Things: How Developers Sort Fields and Methods

We are interested in your opinion!

In many programming languages, fields and methods can be arranged freely, but the order impacts the readability of the code. Which ordering strategy do you apply?

Please answer on stackoverflow.com.

We want to publicly share the different strategies that are applied in practice. You may have already answered this question participating in our questionnaire (thanks a lot!), but we can only publish the results of the survey in anonymized form aggregating the free text answers (see below). Please answer again if you like others to profit from your experience.

Publication

The Order of Things: How Developers Sort Fields and Methods
Benjamin Biegel, Fabian Beck, Willi Hornig, and Stephan Diehl
28th IEEE International Conference on Software Maintenance (ICSM 2012)

Download: PDF

Abstract: In source code files, fields and methods are arranged in linear order. Modern programming languages such as Java do not constrain this order—developers are free to choose any sequence. In this paper we examine the largely unexplored strategies developers apply for ordering fields and methods: First, we use visualization to explore different ordering criteria within three open source Java projects. Second, we verify our observations in a metric-based analysis on an extended set of 16 projects. Third, we present the results of a survey that reflects the opinion and applied ordering strategies of 52 developers. 87% of the participants agreed that ordering of fields and methods is meaningful or important. Our results suggest that there exists a set of criteria repeatedly used for ordering. Among these, the categories defined in the official Java Code Conventions appear to be the primary ordering criterion. However, in the individual strategies of the participants of the survey, we identified 15 ordering criteria additional to the five criteria we considered in the empirical analysis.

Data

We want to share the data and results of our study and invite others to freely use this data for replication or further analyses. We kindly ask to cite our above paper in case you use the data.

I. Project Data

The project data contains all indices and entity properties which are required to compute the metric values introduced in the paper, and hence, are necessary to replicate our experiment.

II. Processed Data

In the paper, we present our results of the empirical analysis in an aggregated manner per project. Thus, to provide a deeper insight into our results, we also offer the metric values we computed for each class.

III. Survey Data

We sent a small survey among developers consisting of seven questions by e-mail to colleagues in research and industry as well to students and asked the recipients for further distributing it among their colleagues. We also posted it in social networks. The survey could be filled in by simply answering the e-mail or by using an alternative (but equivalent) web-form (demo).

We received 55 answers and considered 52 of these for the analysis (two accidental double-submissions as well as a participant declaring he/she did not understand a question were excluded). For replication, we publish this data anonymously and aggregated such that no individual or organization can be identified.

If you require more information, please feel free to contact us. We would further be pleased to receive your comments and suggestions.