Java Code Conventions and Formatting
It is often useful to adopt common code conventions, almost when working on a team or on open source projects.
In modern IDEs, the source code can also be automatically formatted, like in Eclipse.
In Eclipse : Window > Preferences > Java > Code Style > Formatter
Then click Import and pick a file.
You can pick my code style file by example : >> here <<. It will then be available within the current workspace.
As you can see, I don't like much the Sun or K&R style of indentation. I prefer to adopt the Allman style, where the opening and closing braces are aligned vertically.
Right click in the source code, then Source > Format (shortcut : Ctrl + Shift + F).
- Google Java Style (Souce file structure, Formatting, Naming, Programming practices, ...)
- Chapter 5 : Formatting, in Clean Code - A Handbook of Agile Software Craftsmanship - On Amazon