DEV Community

Discussion on: Refactoring JavaScript for Performance and Readability (with Examples!)

Collapse
 
anpos231 profile image
anpos231

I don't know, I actually find the first example of search groups more readable. I'll try to explain why:

I the first example we read the code from top towards down. Whereas in the second example we have additional variables that actually seem to be adding more mess the code than description. In the second example developers eye must float between definitions and the actual code we are reading to get an idea what is going on.

In the first example I can clearly see that there is a two dimensional array with an object at the end. In the second example it's not obvious without carefully studying the code.

Collapse
 
karataev profile image
Eugene Karataev

I prefer the refactored code, because from the variables names it's clear what we're working with.

I guess we need a tool jsRead to measure a code's readability with objective metrics like it's done in jsPerf with performance 😂

Collapse
 
healeycodes profile image
Andrew Healey

Thanks for weighing in! I was hoping some of these would spawn discussion 😊