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 (1)

Collapse
 
madiha_eman_648a237ae79ad profile image
Madiha Eman

Thank you so much for the amazing tutorial, I'll defiantly look into it. I am already using Jsprettier Package for Subline Text. BTW is someone out there is looking for web developers for their project they can contact Wix website design services providers

Some comments may only be visible to logged-in visitors. Sign in to view all comments.