Wednesday, 15 January 2014

On Java code formatting

As a variation of what I wrote in Formatting code for readability here is another example.

Which 'Java source equivalent files' shown below are easier to read?

This one (from FAQ How do I open an editor on something that is not a file?):



Or this one (from StringInput.java):




Note how in the 2nd image:
  • The method names are aligned so they are easier to read and are sorted alphabetically (the last method spoils it a bit since it needs that SuppressWarning attribute)
  • The code brackets ( { and } ) are also all aligned
  • It is easier to quickly read the Method's return type
Post a Comment