DEV Community

Cover image for Code Smell 152 - Logical Comment
Maxi Contieri
Maxi Contieri

Posted on • Originally published at maximilianocontieri.com

Code Smell 152 - Logical Comment

Code Smell 152 - Logical Comment

Code Smell 152 - Logical Comment

Temporary hacks might be permanent

TL;DR: Don't change code semantics to skip code.

Problems

  • Readability

  • Non-Intention Revealing

Solutions

  1. If you need a temporary hack, make it explicit

  2. Rely on your source control system

Context

Changing code with a temporary hack is a very bad developer practice.

We might forget some temporary solutions and leave them forever.

Sample Code

Wrong

if (cart.items() > 11 && user.isRetail())  { 
  doStuff();
}
doMore();
// Production code

// the false acts to temporary skip the if condition
if (false && cart.items() > 11 && user.isRetail())  { 
  doStuff();
}
doMore();

if (true || cart.items() > 11 && user.isRetail())  {
// Same hack to force the condition
Enter fullscreen mode Exit fullscreen mode

Right

if