1. Refuctoring
(The process of taking a well-designed piece of code and, through a series of
small, reversible changes, making it completely unmaintainable by anyone
except yourself.)
2. Code Smells
Well it doesn't have a nose... but it
definitely can stink!
Ingredients
● Comments
● Long Method, Large Class
● Long parameter list
● Duplicated code
● Dead Code
● Temporary variables
● Conditional Complexity
● Combinatorial Explosion
● Uncommunicative/Inconsistent
Names
3. Comments
● The best comment is a good name for a
method or class.
● The code is is supposed to explain itself. In
that case comments are not needed
Comments can be useful
● When explaining why something is being
implemented in a particular way.
● When explaining complex algorithms (when all
other methods for simplifying the algorithm
have been tried and come up short).
4. Long Methods &
Long Classes (God Class)
Classes usually start small. But over
time, they get bloated as the program
grows.
As is the case with long methods as
well,
6. Duplicated
Code
Duplicated code is the bane of
software development. Stamp
out duplication whenever
possible. You should always be
on the lookout for more subtle
cases of near-duplication, too.
Don't Repeat Yourself!
7. Dead Code
● When requirements for the software
have changed or corrections have been
made, nobody had time to clean up the
old code.
● Such code could also be found in
complex conditionals, when one of
the branches becomes unreachable
(due to error or other circumstances).
9. Conditional Complexity
● Watch out for large conditional logic
blocks, particularly blocks that tend to
grow larger or change significantly over
time. Consider alternative object-
oriented approaches such as decorator,
strategy.
11. Uncommunicative/Inconsistent Names
● Does the name of the method succinctly
describe what that method does? Could
you read the method's name to another
developer and have them explain to you
what it does? If not, rename it or rewrite
it.
● $category or $cat ?
● $cat or $c ?
● $subcategory or $SubCategory or
$sub_category or $s_cat or $s_c
12. There are two ways to write
error-free programs;
Only the third one works.(Alan Jay Perlis)
Shobi P P
shobi@storat.com
Reference
https://blog.codinghorror.com/code-smells/