Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Version Control and Coding Formatting

I'm currently part of the team implementing a new version control system (Subversion) within my organization. There's been a bit of a debate on how to handle code formatting and I'd like to get other peoples opinions and experiences on this topic.

We currently have ~10 developers each using different tools (due to licensing and preference). Some of these tools have automatic code formatters and others don't.

If we allow "blind" checkins the code will look drastically different each time someone does a check in. This will make things such as diffs and merges complicated.

I've talked to several people and they've mentioned the following solutions:

  1. Use the same developer program with the same code formatter (not really an option due to licensing)
  2. Have a hook (either client or server side) which will automatically format the code before going into the repository
  3. Manually format the code.

Regarding the 3rd point, the concept is to never auto-format the code and have some standards. Right now that seems to be what we're leaning towards. I'm a bit hesitant on that approach as it could lead to developers spending a lot of time manually formatting code.

If anyone can please provide some their thoughts and experience on this that would be great.

Thank you,

Martin

like image 269
Martin Giffy D'Souza Avatar asked Dec 10 '22 16:12

Martin Giffy D'Souza


2 Answers

Don't let the tools/developers automatically/manually reformat the code just for aesthetic reasons. Diffing between revisions becomes a nightmare. Have a coding standard and try the toolsets to get new modules to conform as best as you can. People modifying an existing module should stick to the conventions used in that module whether they like it or not.

like image 90
Trevor Tippins Avatar answered Dec 21 '22 23:12

Trevor Tippins


If #1 isn't a viable option, #3 is probably your best choice. #2 would make it rather difficult for individual developers to do diffs between a working copy and the existing file after they've checked it out and run their own formatter on it at least once.

Option #3 is mostly about getting people into habits - code formatting isn't really that troublesome if everyone can get into the same habit. The only code you have to format is that which you create/touch; the rest will be formatted from checkout.

like image 31
Amber Avatar answered Dec 21 '22 22:12

Amber