You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
2.2 KiB
47 lines
2.2 KiB
# Code Smell Patterns
|
|
|
|
**Code Smells** are often signs that refactoring could be needed. That is not always the case, but these "smells" should be looked at further to dethermine if there is a need for refactoring.
|
|
|
|
[Duplicated Code](./Duplicated_Code.md)
|
|
|
|
[Excessive Conditionals](./Excessive_Conditionals.md)
|
|
|
|
* Solution: It may be possible to break these conditionals up into smaller, more conscise methods that are easier to read and have a clear purpose.
|
|
|
|
**Reocurring Parameter lists**
|
|
|
|
* Force: Refactoring may be considered if a certian list of parameters keeps reappearing in many methods.
|
|
|
|
For example:
|
|
```
|
|
function(int a, int b, string c)
|
|
function2(int a, int b, string c)
|
|
function3(int a, int b, string c)
|
|
```
|
|
|
|
* Solution: It may be possible to group these parameters into an object and instead pass the object around to different functions rather than passing each parameter.
|
|
|
|
**Big Objects**
|
|
|
|
* Force: Refactoring may be considered if an object has many methods and variables.
|
|
|
|
* Solution: It may be possible to break this object up into a few smaller objects. This can be done for readability, simplicity, and overall funtionality.
|
|
|
|
**Big Methods**
|
|
|
|
* Force: Refactoring may be possible when a method is getting too large. (over 7 lines of active code)
|
|
|
|
* Solution: It may be possible to break this method up into smaller methods. Methods shoudl have a clear purpose and should not take on work it does not have to.
|
|
|
|
**Magic Numbers**
|
|
|
|
* Force: Refactoring may be possible when it is noticed that there are many hard-coded values and and seemingly random literals scattered throughout the code.
|
|
|
|
* Solution: It may be possible to give these vauge "magic numbers" variable names to make the code easier to read, understand, test, and maintain.
|
|
|
|
**Feature Envy**
|
|
|
|
* Force: Refactoring may be possible when it is noticed that a certian object seems to have significantly more features than other objects it is interacting with.
|
|
|
|
* Solution: It may be possible to had work off to some of these smaller objects. If the original object is reaching out to grab things that are much easier access and handled by the secondary object, than a consideration should be made to give that work to the secondary object.
|