Code Smell 123 - Mixed 'What' and 'How'

Photo by Josh Redd on Unsplash

Code Smell 123 - Mixed 'What' and 'How'

Maxi Contieri⭐⭐⭐'s photo
Maxi Contieri⭐⭐⭐
·Mar 22, 2022·

2 min read

Play this article

Table of contents

  • Problems
  • Solutions
  • Context
  • Sample Code
  • Detection
  • Tags
  • Conclusion
  • Relations
  • More Info
  • Credits

We love looking at the internal gears of the clock, but we need to start focusing on the hands.

TL;DR: Don't mess with implementation details. Be declarative. Not imperative.


  • Accidental Coupling

  • Coupling

  • Lack of design for change

  • Comments distinguish the 'how' and the 'what'.


  1. Separate 'What' and 'How' concerns.


Separating concerns is very difficult in the software industry.

Functional software survives ages.

Implementative software brings coupling and is harder to change.

Choosing wise declarative names is a daily challenge.

Sample Code


class Workflow {
    moveToNextTransition() {
        // We couple the business rule with the accidental implementation
        if (this.stepWork.hasPendingTasks) {
            throw new Exception('Preconditions are not met yet..');
        } else {


class Workflow {
    moveToNextTransition() {
        if (!this.canWeMoveOn()) {
            throw new Exception('Preconditions are not met yet..');
        } else {

    canWeMoveOn() {
        // We hide accidental implementation 'the how'
        // under the 'what'
        return !this.stepWork.hasPendingTasks();


[X] Manual

This is a semantic and naming smell.


  • Readability


We need to choose good names and add indirection layers when necessary.

Of course, premature optimizators will fight us, telling us we are wasting computational resources and they need to know the insights we are hiding from them.


More Info


Photo by Josh Redd on Unsplash

The idea of this smell is here:

Code Smell 118 - Return False's comment

and here

We are constantly interfacing with other people's code that might not live up to our high standards and dealing with inputs that may or may not be valid. So we are taught to code defensively. We use assertions to detect bad data and check for consistency.

Andrew Hunt

This article is part of the CodeSmell Series.

Share this