Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thamaraiselvam/9b510a7ea0f096caf85850abaca22445 to your computer and use it in GitHub Desktop.
Save thamaraiselvam/9b510a7ea0f096caf85850abaca22445 to your computer and use it in GitHub Desktop.
Clean Code
Boy Scout Rule:
Always leave the codebase cleaner than you found it
Code Smells:
It is not a bug but hint of problem that makes your code difficult to understand, extend or maintain
Types:
1.Long Method
Method that does multiple things(Againts SOLID Principles)
2. Long Parameter List
function has too many parameters which is hard to maintain and readable
solution: introduce paramter object
3. Feature Envy
Method is more interested in features of another class than its own.
4.Divergent change
it occurs when one class commonly changes in different ways for different reasons.
Solution: Extract Different Classes
5.In appropriate intimacy
classes spend too much time together.
solution: changes bi directional into uni directional flow
Replace Temp with query
-----------------------
Desc: Remove temp varible because that makes refactoring difficult
Solution: Refactor only when it is needed(YAGNI - you ain't gonna need it)
Tests
1.Characterisation Test
before change existing code, write a test case for that code and while refactoring keep on running test to know that we broke anything.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment