Our team has recently inherited code which is extremely disorganized.
As a result, my team leader has decided to enforce a policy of auto-formating of code prior to saving a file. We have even found an option in Eclipse (The IDE of our choice) that auto-formats the code automatically before each save action.
Personally I am against it because I think that proper coding prevents messy code (most of the time) whereas auto-formating does not mean proper coding.
What are your opinions?
Automatic formatting enables higher code quality, especially when you are collaborating in a team and other people need to look at the code you've written. Many developers and organisations maintain standards of code formatting like 2-space or 4-space indentation.
Source Code Format means a form of computer program, or any portion thereof, written in a programming language employed by computer programmers that must be compiled or otherwise translated before it can be executed by a computer.
Press Ctrl+Alt+L/Cmd+Alt+L to automatically fix code formatting in a file.
Java Formatter is a utility class that can make life simple when working with formatting stream output in Java. It is built to operate similarly to the C/C++ printf function. It is used to format and output data to a specific destination, such as a string or a file output stream.
I disagree with you. For me, the formatting, even if it is only a way to "present" the source code, is also an important code quality indicator.
Using the auto-formatting has several advantages. It homogenizes the format among all the developers of the team. This will avoid you some troubles with the SCM manipulation: for example, merging two files that have few real changes, but a lot of formatting differences is a nightmare!
It can also show you some errors. For example:
if (aCondition)
foo();
bar();
will be reformatted:
if (condition)
foo();
bar();
showing that the second line is not in the if
statement.
Last, but not least, a well formatted code (not only for Java) is easier to read!
Auto-format the inherited code just once, and then proceed without auto-formatting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With