Code Smell 03 — Functions Are Too Long

Humans get bored beyond line 10.

Maximiliano Contieri
Dev Genius

--

Photo by Hari Panicker on Unsplash

Problems

  • Low Cohesion
  • High coupling
  • Difficult to read

Solutions

1) Refactor

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

3) Compose methods

Examples

  • Libraries

Sample Code

Wrong

Right

Detection

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

Also Known as

  • Long Method

More info

Tags

  • Complexity

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

Donald Knuth

--

--

I’m a senior software engineer specialized in declarative designs. S.O.L.I.D. and agile methodologies fan. Maximilianocontieri.com