DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Tips for Implementing Code Standards

Implementing code standards is a lot harder than it seems. Here are a few tips to make rolling out your own standards easier.

Matthew Casperson user avatar by
Matthew Casperson
·
Nov. 26, 16 · Opinion
Like (3)
Save
Tweet
Share
9.14K Views

Join the DZone community and get the full member experience.

Join For Free

At some point, a code base and the development team that contributes to it will reach a point where standards become a necessity. There are many reasons for implementing coding standards: ensuring merges don’t include unnecessary conflicts, enforcing good practices that aren’t inherent to a programming language and ensuring consistent expectations during code review are just a few reasons.

But implementing code standards is actually a lot harder than it seems. Here are a few tips to make rolling out your own standards easier.

Let Someone Else Do the Work

Companies like Google publicly document their coding standards. In fact, they also publish tools to autoformat code to comply with their standards. Don’t underestimate the value of reusing these standards and tools.

If it is an option for you, adopt the requirements that have already been put into place by people who have already created a set of standards that has proven to be effective.

Plan for Disagreement

Tabs vs spaces. You all know the arguments I’m talking about. Ask 10 developers what their opinion is, and you’ll get 12 different answers.

When it comes to drafting a style guide, arguments like this will bite you every step of the way. If it is not tabs vs. spaces, it is single quotes vs double quotes, camel case vs snake case, self vs me... The list goes on.

If you do choose to draft your own style guide, abandon any expectation that everyone will agree, and adopt some kind of strategy to effectively resolve these arguments. You could take a vote or nominate an arbiter. But have this resolution strategy in place before the arguments get out of control.

Start Small

Too often code standards are dropped like a bombshell, demanding compliance with hundreds of esoteric rules that fail in code that was until recently considered perfectly valid. It is incredibly frustrating to try and accommodate these new rules, and can get to a point where it is so overwhelming that developers will just disable style checking all together.

It is often best to start small by enforcing a limited number of style rules and build from there. Once the practice of verifying code standards becomes part of the development routine, you can start adding more onerous standards.

Don’t Mix Tools

There are dozens of different tools for enforcing coding standards. Your IDE will probably have some style checking built in, while external tools can also be configured to enforce rules. But the various different code style enforces available to you will almost never have the same functionality, and getting them to play nice together just doesn’t work.

Pick one tool and stick with it. Resist the temptation to combine style checkers, because the end result will just frustrate developers and result in code standards being ignored entirely.

Aim to Break the Build

Breaking the build when a code style violation is detected can be harsh and frustrating for developers just trying to get code out the door, but in the long run, it is the most effective and fair way to enforce the rules.

Getting to this point can be hard if you have a lot of existing code that was written before coding standards were introduced, and you may find yourself implementing interim measures like only enforcing standards on new code being committed. But your ultimate goal should be to treat code style violations like any other compiler error and break the build.

Published at DZone with permission of Matthew Casperson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Apache Kafka vs. Memphis.dev
  • Core Machine Learning Metrics
  • How to Quickly Build an Audio Editor With UI
  • Why Every Fintech Company Needs DevOps

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: