I'm using Eclipse and I will talk about it as an example but I am sure that this is the case in any other IDE.

Eclipse has the CTRL-Shift-F command which automatically formats your code. Is it a good practice to use this kind of formatting?
I'm asking in the context of a big project in which there may be many programmers working on the same files and all these are administrated by a CSV system.

4 Answers
4

Eclipse lets you define your own exportable code style which you can share among all your developers. If you don't want to setup your own formatting style, you may tell your developers to use Eclipse's default formatting. Even if you use the default one, I would advise you to export it and put it on a shared network drive for all developers to use. If later one, you decide to change one thing, you'll be able to easily.

Regardless, I would advise you to start as soon as possible, the best would be at the beginning of the project, and to keep your code always formatted to your chosen format. You'll want to avoid having pure "format commits" during the development because it's hard then to distinguish from "real" commits. What it means in practice is that developers should be rigorous with their commits.

Also, and I put it at the end because it is only my personal opinion, but consider removing the 80 characters per line limit (or extend it to something bigger, we have 120 characters here) which is, if I'm not mistaken the default auto-formatting line-length on Eclipse. We now all have big screens and big screen resolutions so it's ok. On that subject, check out the Is the 80-character limit still relevant in times of widescreen monitors question and answers, you may then be able to make your own decision.

Edit: Thorbjørn makes a good point about the "Format every time a file is saved" functionality.

The reason is naturally that code is always formatted, so you can format at will when editing without fearing anything breaks. This also ensures that the source repository logs are accurate (which is important when doing forensic analysis).

It is a good practice to follow a well-defined coding standard in a project/company. The means of doing it though can vary, just pick whatever works best for you organization. If everyone uses Eclipse then you could just create an exportable code format for your projects and spread it between developers (Eclipse also has an option to format files automatically on each save), however I would recommend creating a document describing the chosen format.

You should have a coding standard that you all follow. Whether this is enforced by external tools (such as indent), or IDE, or by hand is kind of irrelevant. What is relevant is that it should be done any before commit.