How to write Clean Code

How to write Clean Code

Clean Code include:

  1. Use Meaningful Names - Make it a habit to give your code meaningful names

  2. Make Code Readable For People - There's always the possibility that another human will discover your code and have to work with it

  3. Use Comments For Clarification - Developers frequently use comments to describe the purpose of a line in their code

  4. Single Responsibility Principle - A good technique to arrange code is to use classes, functions, or methods. They need to be small. They should just focus on one subject and do it well

  5. Make Your Project well organized -This is a fairly typical problem in software development, when we add and delete a large number of files or directories in our project, making it difficult and inconvenient for other developers to understand and work on it

Is Short Code Always Better code ?

  • Any knucklehead can write computer-readable code. Human-readable code is written by good programmers

  • So, while shorter code does not always imply better code, it can. The point is, how can we know which Code is good and which is bad?

3 Golden Rules:

  1. Readability

  2. Maintainability

  3. Efficiency

Readability

  • You should keep in mind that your source code may be difficult to understand for other engineers. As a result, you must make your code simple and quick to understand

Maintainability

  • It's difficult to keep track of short, cryptic code. It could lead to issues such as glitches and increased overhead expenditures during quality control

Efficiency

  • Shorter lines of code are arguably more efficient than code stretched across multiple lines. There are more locations for bugs to hide if you have more lines of code

  • A smaller number of lines of code can achieve the same result as a larger number of lines of code. You can reduce the number of bugs in a task by reducing the amount of code in it, especially if the source code is clear, legible, and maintainable

Conclusion

  • The use of a short code does not always imply that it is superior. Short Code is preferable if it is readable and manageable; but, if it is not, the longer Code is the better option