Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inherited code: To format or not to format? [closed]

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?

like image 627
Yaneeve Avatar asked Nov 04 '09 14:11

Yaneeve


People also ask

Should you format your code?

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.

What does it mean to format your code?

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.

How do I fix code formatting?

Press Ctrl+Alt+L/Cmd+Alt+L to automatically fix code formatting in a file.

What is the use of formatter in Java?

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.


2 Answers

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!

like image 65
Romain Linsolas Avatar answered Oct 05 '22 22:10

Romain Linsolas


Auto-format the inherited code just once, and then proceed without auto-formatting.

like image 30
Grumdrig Avatar answered Oct 05 '22 22:10

Grumdrig