Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Follow publication

Code Smell 74 — Empty Lines

Maximiliano Contieri
Dev Genius
Published in
1 min readJun 4, 2021

Photo by Sigmund on Unsplash

TL;DR Don’t add empty lines to your methods. Extract them!

Problems

  • Readability
  • Kiss
  • Low Reuse

Solutions

1. Extract Method

2. Refactor

3. Remove unneeded lines.

Sample Code

Wrong

Right

Detection

This is a policy smell. Every linter can detect blank lines and warn us.

Tags

  • Readability
  • Long Methods

Conclusion

Empty lines are harmless, but show us an opportunity to break the code into small steps.

If you break your code with comments, it is also a code smell asking for a refactor.

Relations

It’s OK to figure out murder mysteries, but you shouldn’t need to figure out code. You should be able to read it.

Steve McConnell

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Written by Maximiliano Contieri

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

Responses (7)

Write a response

I hope a linter doesn't actually enforce this. That'll just encourage people to remove blank lines, not to refactor their methods.

--

My first thoughts were similar to some of the previous comments to this post, 'no wait this feels somewhat off'.
Hoewever looking at it though the lense of 'if you find that you are splitting the definitions using whitespace then you should use that…

--

In cases where the spaces are separating different sections of a function that could be independent from each other, this makes sense. Other scenarios, not too much.

Most of the time I’m using empty lines in a function, it is to *improve*…

--