Principle of Clean Code
Principle of Clean Code
Keep it simple, stupid (KISS), you aren’t gonna need it (YAGNI), and don’t repeat
yourself (DRY) are some of the most powerful digital product design principles.
They lay the foundations for best practices that developers use to build better
products every day.
This principle suggests that code should not have unnecessary duplication.
Instead, it should be organized in a way that avoids redundancy and makes it easy
to maintain.
For example, instead of writing the same calculation in multiple places in the
code, create a function that performs the calculation and call that function from
the different places where the calculation is needed.
println(7 * 1);
println(7 * 2);
println(7 * 3);
println(7 * 4);
println(7 * 5);
println(7 * 6);
println(7 * 7);
println(7 * 8);
KISS:
The variable names in a program should serve their purpose well. They
should be able to define the variable properly
Method name should also be in line with the purpose for which the method
is employed
As mentioned in an earlier example in the DRY principle, comments in the
method should be used only when your program is not able to define the
method completely
Classes should be designed in a way to own a single responsibility
Delete redundant processes and algorithms as explained during the DRY
process
It is vital to apply the KISS principle when you are working on the
modification of an existing codebase. It helps clean the code and make it
more readable and editable
Application of this principle helps in maintaining continuity in the
development of a code when the programmer changes.
KISS principle enhances the efficiency during automated testing of the
code.
Fewer chances of errors during coding.
YAGNI: