Others

Objectifying Code Quality

May 9, 2023

Coding is an art. As the number of artists increase the art start to loose standard.

What Is Quality Code?

  1. Readable
  2. Portable
  3. Robust
  4. Reliable
  5. Efficient
  6. Maintainable

Millions of lines of code written everyday, hundreds of deployments every day introduced to end user to be consumed on scale.

This code needs to be of highest quality in order to remain alive, and keep making the user happy.

What is bad quality code?

Even the shittiest of code pieces many a time does what need to be done. But in the long haul it causes pain to people who are either using or maintaining it.

  1. Not Formatted
  2. Not well thought
  3. Doesn’t have test
  4. Big chunk
  5. Uses cryptic / non meaning full identifiers

How Can We Quantitatively Represent Code Quality?

A quality measure can be represented by the measure of its constituents.

We can use below means to check if the code is alright.

  1. Linters
  2. Formatter
  3. Style guides
  4. Review Comments

According to Wikipedia,

linter is a tool that analyses source code to flag programming errors, bugs, stylistic errors, and suspicious constructs

Linter actually uses a popular style guide or a set of rules and then checks if a rule is failing or implemented improperly. Most linters provides –fix options to remove the problems while some are dependent on code formatter like prettier(for js) or black (python).

Okay, So..

Yes we have these tools, And they help us write better code, but how they flag a bad code.

Counts!!! By giving you counts of lint/ rule fails you can set a threshold like

  1. no more than 10 lint errors.
  2. no formatting errors or
  3. the x style guide should be thoroughly followed

All these stuffs things can be broadly taken into account as below metrics

  1. Bugs
  2. Code Smells
  3. Vulnerabilities
  4. Coverage
  5. Duplication
  6. Lines

Leave a Reply

Your email address will not be published. Required fields are marked *