cover-img

Code Smell 74 - Empty Lines

Breaking the code to favor readability asks for refactoring.

1 June, 2023

2

2

0

Breaking the code to favor readability asks for refactoring.

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

<?

function translateFile() {
$this->buildFilename();
$this->readFile();
$this->assertFileContentsAreOk();
// A lot of lines more

// Empty space to pause definition
$this->translateHiperLinks();
$this->translateMetadata();
$this->translatePlainText();

// Yet Another empty space
$this->generateStats();
$this->saveFileContents();
// A lot of more lines
}

Right

<?

function translateFile() {
$this->readFileToMemory();
$this->translateContents();
$this->generateStatsAndSaveFileContents();
}

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

Code Smell 03 - Functions Are Too Long

Code Smell 75 - Comments Inside a Method

Credits

Photo by Sigmund on Unsplash


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

Software Engineering Great Quotes


This article is part of the CodeSmell Series.

How to Find the Stinky Parts of your Code

2

2

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.