DEV Community


Discussion on: Refactoring the Worst Code I’ve Ever Written

vfonic profile image

Wow! Great to see such a progress! When I saw your initial code, I couldn't come up with an easy way to "DRY" it. :)

What you did is a great job. That also goes for the other "Options" you added later.

One thing that caught my eye:

Every time the user makes a selection, this method will run. Depending on the size of that dataset (remember, it grows every year), there could be a negative impact on performance. Modern browsers are efficient and the performance hit might be minuscule, but if we already know that the user can only select 1 type and 1 year at a time, we can be proactive about improving performance by grouping the data from the beginning. performance. Yes, some other users already mentioned it. :)
I think we (me too) generally think too much about performance. One great book that I'm reading right now is Martin Fowler's "Refactoring" (pun? :D). In it, he writes, and I agree, to not be so strict about performance. Usually performance bottlenecks are in the parts of the apps we don't think they are.
I'd just add that without a benchmark, we are both just playing poker with no cards in the hand. :)
I'd just advise against even mentioning performance. If you're not writing the next react, just ignore it for this use-case.

Forem Open with the Forem app