DEV Community

Aaroh Mankad
Aaroh Mankad

Posted on

Cleaning Up Your Code: Consistent Formatting

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!)

Airbnb Style Guide for Javascript
Google Style Guide for C++
PEP8 Style Guide for Python

If you're working in Javascript, I highly recommend using Prettier to automatically handle the formatting for you! I use the JsPrettier Package for Sublime Text.

Thanks for reading! How do you enforce consistent code-style in your projects?

Top comments (0)