An Interest In:
Web News this Week
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
October 15, 2022 01:46 am GMT
Original Link: https://dev.to/mcsee/code-smell-169-glued-methods-2h8l
Code Smell 169 - Glued Methods
Don't make two or more things at once.
TL;DR: Try to be as atomic as possible in your methods
Problems
Coupled Code
Harder to test
Harder to read
Solutions
- Break the method
Refactorings
Refactoring 002 - Extract Method
Maxi Contieri Nov 25 '21 2 min read
#refactoring #oop #webdev #codenewbie
Context
If you name a method with 'And' you are probably missing an extract-and-break method opportunity.
Sample Code
Wrong
calculatePrimeFactorsRemoveDuplicatesAndPrintThem()// Three responsibilities
Right
calculatePrimeFactors();removeDuplicates();printNumbers();// Three diferent methods// We can test them and reuse them
Detection
[X] Semi-Automatic
Some linters can warn us about methods including the term 'and'.
Tags
- Coupling
Conclusion
When making methods, it is very important to play some rubber duck story and tell ourselves if we are making things right.
Relations
Code Smell 85 - And Functions
Maxi Contieri Aug 21 '21 1 min read
#oop #programming #webdev #codenewbie
Disclaimer
Code Smells are just my opinion.
Credits
Photo by Scott Sanker on Unsplash
Learning the art of programming, like most other disciplines, consists of first learning the rules and then learning when to break them.
Joshua Bloch
Software Engineering Great Quotes
Maxi Contieri Dec 28 '20 13 min read
#codenewbie #programming #quotes #software
This article is part of the CodeSmell Series.
Original Link: https://dev.to/mcsee/code-smell-169-glued-methods-2h8l
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To