DEV Community

Discussion on: Refactoring Chronicles: Conditional Rendering and getting rid of the Wrapper Div

Collapse
 
daniel13rady profile image
Daniel Brady

I doubt this would be a more readable improvement

I'm glad to find someone else giving "readability" feedback in code reviews!

In 5 years, I've gone from a "how concisely/cleverly can I write this?" approach to coding, to a "how well can someone with no context read what I've written?" approach. And it I've experienced nothing but good things from making that shift.

Collapse
 
dvddpl profile image
Davide de Paolis

often "readability" it is just a matter of habit. I remember when I moved to Javascript at the beginning I found very hard reading the Arrow functions
consider this

function multiplyByTwo(a) {
     return a*2;
}

versus :

const multiplyByTwo = a => a*2

Back then I would argue that the more verbose way was more understandable, right now i prefer the concise version.

It contains only what matters, no clutter.

But I completely agree that ( unless when there are performance issues or other reasons ) it is much better to write small (tiny) methods that can be compose together rather than a big one with lots of stuff in it.
Just think about a single for loop which filters and sorts and concatenate and manipulate data vs 4 different functions all concatenated. sure it's one iteration vs 4 but code is more readable and more unittestable.
And as you said reducing the cognitive load, and the amount of context you need to have to understand a piece of code is the most important thing.