This is an excerpt from my article "Cleaning Up Your Code" on Medium. I'll be publishing each section daily, read ahead on Medium!
An age-old debate: tabs or spaces? Braces on the same line or new line?
I’m not going to suggest any specific formatting, but I do want to expose you to some guidelines on deciding formatting for your project. First and foremost, once you’ve found a method of formatting to use, stick to it.
There’s two steps to getting most of the way to a perfect style guide for your project.
- Pick a popular style guide for your language. Picking a style guide that more people have been exposed to will reduce the time a new contributor focuses on syntax and more time on making meaningful contributions to your code. Examples are included below.
- Make slight variations to it for your specific use cases. If a certain point in your chosen style guide doesn’t make sense for your use case, document it. (Ideally in a CONTRIBUTING.md file!)
Thanks for reading! How do you enforce consistent code-style in your projects?