DEV Community

Cover image for Code Smell 123 - Mixed 'What' and 'How'
Maxi Contieri ⭐⭐⭐
Maxi Contieri ⭐⭐⭐

Posted on • Originally published at


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

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 {
Enter fullscreen mode Exit fullscreen mode


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();
Enter fullscreen mode Exit fullscreen mode


[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.

Top comments (0)

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.