Today I am doing another smells blog post but this one is going to about code instead of design. This article that I am doing it on contains many of the code smells and I will be being writing about some of the things I learned from them. First, code smells within codes:
Comments – I learned to remember that comments should be written for people, not the machines. I will also try to refactor my code as possible to avoid to comments for example better method names and cleaner code, so it would be easier to understand and follow.
Long Method – I learned that shorter method is better than longer method because it is easier to read, understand, and maintain. I will always try to minimize the size of my method as small as possible to be more efficient.
Long parameter list – I learned a great to limit the number of parameters by using a object to combine it if I actually need the values of the parameters because the more parameters there is, the more complex it is.
Duplicated Code – never have code that duplicated.
Conditional complexity – don’t have large conditional logic block, use design patterns to avoid this problem.
Combinatorial explosion – I learned that this is when we have lots of code perform the same operation but have a little difference. I think the best way to avoid this is to make a method for the operation.
Large class – if a class seem too large than you can break it into smaller class, so it can be easier to understand.
Large class – if a class seem too large than you can break it into smaller class, so it can be easier to understand.
Also, Code smells between classes:
Data class – I learned to avoid class that only data because a class should have data but should have method to manipulate the data.
Lazy class – this just means that every class should be important enough to be a class.
Shotgun surgery – this means that you should avoid making a class that effect other classed when making an update.
Solution Sprawl – this is when you have need multiple class to do one thing, it’s better off to simplify the code.
All in all, this article has All in all, this article has code smells and I learned a lot from them. I now know how to avoid these smells and how to deal with them after reading this.
https://blog.codinghorror.com/code-smells/
From the blog CS@Worcester – Phan's CS by phancs and used with permission of the author. All other rights reserved by the author.