Clean Code Overview

Code that is easy to understand is clean code. It can be read and enhanced by a developer other than its original author, which makes it more changeable, extensible and maintainable. The cost of testing and maintenance can also be significantly reduced with efficient coding.

Read more about it here.

Object Oriented Concepts

Object-Oriented Programming (OOPs) Concept helps in reducing the code complexity and allows the reusability of code. OOPs is a programming paradigm that brings together data and methods in a single entity called an object. 

Read more about it here.

Naming Conventions

We will be naming lots of variables, classes, and methods in a codebase. According to Robert Cecil Martin also known as Uncle Bob in Clean Code, we should name a variable with utmost care and the name should convey the intent of its creation. The “intention-revealing” names will save you more time in the long run, save everyone's time, and prevents a snowball of bad things from happening to the precious code. The names we choose should answer the big questions:

  1. Why does it exist?
  2. What does it do?
  3. How is it used?

Read more about proper naming conventions here.

Magic Numbers

A magic number is a number in the code that seems arbitrary and has no context or meaning. One of the most important aspects of the quality of code is how it conveys intention. Magic numbers hide intention so they should be avoided. Magic numbers also make our code brittle and harder to change. 

The recommended approach is to create a constant to represent the value. This will improve the readability of the code and make it easier to modify in the future.

Read more about it here.

Writing Good Functions/Methods

Functions are one of the most important parts of writing code. They make the code reusable, and easy to read and maintain. Functions make the code organized.

A good function should have the following properties:

  • Should be small
  • Should do just one thing
  • Should have fewer arguments
  • Should not have side-effects

One should be able to look at the function name and understand what that function does.

Read more about it here.

Don’t Repeat Yourself (DRY)

Duplication of code can make code very difficult to maintain. Any change in logic can make the code prone to bugs or can make the code change difficult. This can be fixed by doing code reuse (DRY Principle).

The DRY principle is stated as "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system". The way to achieve DRY is by creating functions and classes to make sure that any logic should be written in only one place.

Read more about it here.

Single Responsibility Principle

The Single Responsibility Principle states that there should never be more than one reason for a class to change. In other words, every class should have only one responsibility. If there are two reasons to change a class then it has more than one responsibility and should be split. Having multiple reasons to change means that the module has high coupling.

Read more about it here.

References

Video Links

  1. https://www.youtube.com/watch?v=SPlS4kW0UbE&ab_channel=CodingTech
  2. https://www.youtube.com/watch?v=D4auWwMsEnY&t=96s&ab_channel=CodingTech
  3. https://www.youtube.com/watch?v=OVf0xP4BLq0&ab_channel=SkyBetting%26GamingTechnology
  4. https://www.youtube.com/watch?v=5DFUH0zCn3Y&ab_channel=WolfSound
  5. https://www.youtube.com/watch?v=JnFh2NoAM4s&ab_channel=WebDevSimplified
  6. https://www.youtube.com/watch?v=2lD8fjedeis&ab_channel=Rebeloper-RebelDeveloper

Clean Code principles

  1. https://gist.github.com/wojteklu/73c6914cc446146b8b533c0988cf8d29
  2. https://betterprogramming.pub/12-conventions-for-writing-clean-code-e16c51e3939a
  3. https://workat.tech/machine-coding/tutorial/introduction-clean-code-software-design-principles-nwu4qqc63e09
  4. https://x-team.com/blog/principles-clean-code/
  5. https://www.baeldung.com/java-clean-code
  6. https://www.freecodecamp.org/news/clean-coding-for-beginners/
  7. https://garywoodfine.com/what-is-clean-code/
  8. https://www.codebyamir.com/blog/software-anti-patterns-magic-numbers
  9. https://workat.tech/machine-coding/tutorial/design-good-functions-classes-clean-code-86h68awn9c7q
  10. Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin (Uncle Bob).
  11. https://thecoderoad.blog/2020/03/29/clean-code-naming-conventions/

Geektrust Clean Code Videos

  1. https://www.youtube.com/watch?v=FcZC1WI6xsg&t=4s&ab_channel=Geektrust
  2. https://www.youtube.com/watch?v=HGDeH8bRB-0&t=5s&ab_channel=Geektrust
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us