Picking a code formatting style at work

Feb 1, 2014

At the office, a manager recently picked random people from every team and tasked them with deciding on a common code formatting style that would then be enforced on the entire codebase. The tool that will be used for performing the actual formatting is astyle. His plan was for the group to talk to everyone in their respective teams and settle upon a style that would be acceptable to most of our colleagues. I happened to be one of two guys picked from my team for this, and I also happen to know how hard it is to get people to decide anything in a meeting. Having a meeting with 30-odd people and getting them to settle on a commonly-agreed-upon formatting style would be next to impossible. So I decided to just create a web-based tool that would let everyone vote for their preferred combination of formatting options (astyle offers a whole lot of them), and the most-voted options would then be enforced.

I used sundown to format the style examples on astyle’s documentation page, and then created a webpage of my own that lists each option available next to an example of what that option would do. Also next to each option is a vote button for a user to indicate that he/she likes that option. After any voting change, the currently-voted options are POSTed to the server as a space-separated string, thereby removing the need for a “Save” button. Instead of worrying about usernames and passwords, I require users to enter their office email address and then email them a link that is unique to their account. I picked nosql for my database since all I need to store is a user’s email address, the private link for their account and the options that they have voted for.

All in all, the whole thing took me about 8 hours to finish, and it looks pretty nice even if I do say so myself. The code can be found at node-astyle if anyone is interested.

Astyle formatting-style chooser