Code Smell 03 - Functions Are Too Long

Code Smell 03 - Functions Are Too Long

Maxi Contieri
·Oct 22, 2020·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Humans get bored beyond line 10.

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


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


1) Refactor

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

3) Compose methods


  • Libraries

Sample Code



function setUpChessBoard() {

    //A lot of lines

function setUpChessBoard() {


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


Also Known as

  • Long Method

More info


  • Complexity


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


Photo by Hari Panicker on Unsplash

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

Donald Knuth

This article is part of the CodeSmell Series.

Last update: 2021/06/01

Share this


Technical Opinions are my own. I don't have the revealed truth.

Software Design is a creative activity. These are hints and not rigid rules.

I write on BackEnd Business Systems and OOP Design. My advice/experience might not suit other systems.

You can write me at info(at)