DEV Community

Discussion on: 9 Tricks To Write Less JavaScript.

jamesthomson profile image
James Thomson

When you work with and review thousands of lines of code per day you want clean legible code. Scanning code vertically is more efficient. Writing a couple extra lines greatly helps the reviewers and maintainers.

Thread Thread
jpantunes profile image
JP Antunes

Agreed, but I also want to point out that making extra lines of code that helps you reason better doesn't make the code more readable at all. In fact, it can make your code thousands of lines long when a a dozen might do the job with less bugs.

Thread Thread
jamesthomson profile image
James Thomson

We’re only talking variables here. Besides, with destructuring and using modules your files should never be that big.

Thread Thread
jpantunes profile image
JP Antunes

I think we are talking about different things. I replied to PatricNox's comment with an example that takes less LOCs and is imho less error prone. What were you replying to?

Thread Thread
jamesthomson profile image
James Thomson

This

Agreed, but I also want to point out that making extra lines of code that helps you reason better doesn't make the code more readable at all. In fact, it can make your code thousands of lines long when a a dozen might do the job with less bugs.

Thread Thread
jpantunes profile image
JP Antunes

Oh, that's not about variables at all, it's really about what happens inside a function and what should be outside it.

Both examples of uninitialised variable declarations let a, b, c = 1 or let a; let b; let c =1 or even let [a,b,c] = [,,1] are code smells imho, it just looks messy and error prone.

Thread Thread
jamesthomson profile image
James Thomson

Ah I see, then I think we are talking about different things. The max thread levels makes this confusing.

And I agree about undefined variable declarations.