You’re reading an excerpt of my upcoming book on clean code, “Washing your code: write once, read seven times.” Preorder it on Leanpub or read a ...
For further actions, you may consider blocking this person and/or reporting abuse
Great article! I use all the same principles in code.
2 more case I'd like to mention:
1.Often we need to check some condition and throw error. E.g.:
To remove such boilerplate I use throw-utils library:
2.When we need to return value from function or throw an error:
It can be also simplified with
throwErrorutility method:In "deduplicating" I would even coerce it to a single line:
counts[url] = (counts[url]||0) + votesI can never get over the shame of
(products || []).map(.Who knows what other things I will be doing with the resulting empty array afterwards?!
I always break out to imperative to do a
I would find the whole horns&hooves stuff a lot more readable with ternary operators instead of this function array construct.
I would instead write as:
Although I agree that the original example wasn't the most readable, I don't think that your example would scale very well. If you moved the declaration of the object out of the function (possibly to a different file) and access the value the way that Artem did I think you would have a much more readable function. But that's just my opinion :)
Excellent article! 👏