loading...

The Stepdown Rule in Javascript

l222p profile image l222p ・1 min read

I have been reading about Uncle Bob and The Stepdown Rule caught my attention, I totally agree wit him since is makes your code readable. He defines this Rule as:

The code in our class should be readable from top to bottom, descending one level of abstraction per function

There is a keyword, class. Often, I write code using a functional approach and as you may know let and const are hoisted to the top of the block, so this should throw an exception

sayHi();

const sayHi = () => {
    console.log('Hi')
}

In order to execute I should have user the function keyword, this way:

sayHi();

function sayHi() {
    console.log('Hi')
}

Howeve ESLINT doesn't agree, it has a rule about it.

https://eslint.org/docs/rules/no-use-before-define

Can we say that the Stepdown Rule should apply on OOP? Should I follow the eslint recommendation? What do you think? Let's chat in the comments :)

Posted on by:

l222p profile

l222p

@l222p

Software Engineer focused on Web Development and Cloud Computing

Discussion

pic
Editor guide