DEV Community

loading...

Discussion on: When is nesting good or neutral?

Collapse
jmau111 profile image
Julien Maury • Edited

A lot of people (we) would consider nested html div bad cause it could be easily done with one container which is here "section" (source). So it's bloat !

Take JavaScript, in fact promises are supposed to prevent any callback hell. But that is not enough cause people (we) nest things (especially promises) so we have now async and await.

JavaScript supports nested functions so people (we) nest functions but it turns to be almost unreadable so we have now functional programming where functions are, instead, composed and piped.

In short I'd say nesting can be really really bad (especially for debugging and readability) but chaining, piping, composing is often a good choice.

But code can be bad without being nested at all and when I read this :

if ( A ) {

    if( B & C ) {

    } else { }

} else {}

it's totally palatable and it's not my top priority to refactor. Am I wrong ?

Forem Open with the Forem app