DEV Community

loading...
Cover image for Code Smell 48 - Code Without Standards

Code Smell 48 - Code Without Standards

mcsee profile image Maxi Contieri Updated on ・1 min read

Working on a solo project is easy. Unless you go back to it after some months. Working with many other developers requires some agreements.

Problems

  • Maintainability

  • Readability

Solutions

  1. Automate your styles and indentation.

  2. Enforce agreed policies.

Sample Code

Wrong

Correct sample taken from Sandro Mancuso's bank kata

Right

The Right example has several other smells, but we keep it loyal to its GIT version in order to show only code standardization issues.

Detection

Linters and IDEs should test coding standards before a merge request is approved.

We can add our own naming conventions related to Objects, Classes, Interfaces, Modules etc.

Examples

Tags

  • Standardization

Conclusion

Use coding standards in your projects.

A well-written clean code always follows standards about naming conventions, formatting and code style.

Such standards are helpful because they make things clear and deterministic for the ones who read your code, including yourself.

Code styling should be automatic and mandatory on large organizations to enforce Collective Ownership.

Relations

More info

Naming Conventions


The nice thing about standards is that there are so many to choose from.

Andrew S. Tannenbaum

Discussion (1)

Collapse
darkwiiplayer profile image
DarkWiiPlayer

a while ago I started adding tests to my projects that check indentation and it has saved me from many accidental space-indented commits already 😁

Forem Open with the Forem app