cover-img

Code Smell 03 - Functions Are Too Long

15 July, 2022

6

6

0

Humans get bored beyond line 10.

TL;DR: Refactor and extract functions longer than 5 lines.

Problems

  • Low Cohesion
  • High coupling
  • Difficult to read
  • Low Reuse

Solutions

  1. Refactor

  2. Create small objects dealing with some tasks. Unit test them.

  3. Compose methods

Examples

  • Libraries

Sample Code

Wrong




Detection

All linters can measure and warn when methods are larger than a predefined threshold.

Relations

-https://maximilianocontieri.com/code-smell-102-arrow-code

Also Known as

  • Long Method

More info

Tags

  • Complexity

Conclusion

Extract long method into smaller pieces. Break complex algorithms in parts. You can also unit test these parts.

Credits

Photo by Hari Panicker on Unsplash


Programs are meant to be read by humans and only incidentally for computers to execute.

Donald Knuth

https://maximilianocontieri.com/software-engineering-great-quotes


This article is part of the CodeSmell Series.

6

6

0

Maxi Contieri

Buenos Aires, Argentina

🎓Learn something new every day.📆 💻CS software engineer 👷coding👨🏽‍🏫teaching ✍🏾writing 🎨Software Design 🏢SOLID 🌉TDD 👴Legacy 💩Code Smells

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2024. Showcase Creators Inc. All rights reserved.