Skip to content

Code Formatting

Jon Freer edited this page Nov 2, 2018 · 2 revisions

so... tabs or spaces?

Enforcing a Standard Set of Conventions

When it comes to formatting code, every engineer will have a bushel of preferences. Often times these formatting choices have benefits deeply rooted in pragmatism, while others have been the source of holy wars. There reaches a point in a programmer's career where they realize that every codebase is different, and the way code is formatted is up to either formal policies enforced by an entire organization, or more casual guidelines upheld by team members.

For noti, we have chosen to adopt Google's Java style guide. Google has invested a fair share of time drafting style guides for many languages other than Java, and even provide tools to reformat the code (here is one for Java) according to their style guides.

Benefits

By choosing a more commonly adopted set of conventions, the benefits include:

  • shields the codebase from disperse personal preferences, opinions, and bias of the contributing engineers
  • prevents conflicting outlooks from contributing engineers to impact productivity
  • displaces any displeasure with the conventions away from any contributing engineer
  • programmatic enforcement of the conventions using available tools
  • an actively maintained set of guidelines owned by an authoritative source

Automatic Enforcement

Instead of having to ensure you write your code in a way that conforms to Google's Java style guide, we decided to automate the formatting process by utilizing a Maven plugin to do the job automatically.

You should be able to get by without ever needing to worry about formatting your code. The formatting is automatically applied when executing common Maven commands such as mvn compile and mvn package. If you want to format your code without performing any other operation, invoke the following command within the root directory of the project:

mvn com.coveo:fmt-maven-plugin:format

Clone this wiki locally