Don't blindly refactor code

preview_player
Показать описание

#javascript #typescript
Рекомендации по теме
Комментарии
Автор

This advice is Solid. I tried refactoring my very first micro service and in the end not much was done. Came back to it like 3 months later, realized a completely different method.

thydevdom
Автор

Premature optimization or abstraction can indeed lead to significant maintenance challenges. However, your analogy may not be entirely accurate as the second code appears to have removed existing features, which is not considered premature refactoring but rather reckless modification. Nonetheless, I appreciate your enthusiasm and encourage you to continue your efforts.

emjaytripleo
Автор

I generally don't refactor code by removing lines, I rather break it into individual pieces and shorten them, eventually leading to cleaner code

k_gold
Автор

First code looks good to me! No refactoring necessary 😊

amitd
Автор

Personally, I'd split the logic out further into separate functions, there's still a bit much going on in this one for my liking.

Either fetchUserDataFromApi and fetchUserDataFromCache etc

Or add a generic cache wrapper in the calling function.

Either way, if the function interacts with the cache or the api, it's courteous for the function name to convey that.

If a function contains more than one return statement, I'm always suspicious that it has too much responsibility. In this case, the function does multiple things directly, ideally we just want it to do one thing, return the user data from either the cache or the api, but it doesn't need to be responsible for creating cache keys, invoking cache and api lookups etc. The less code there is in a function, the easier it is to reason about.

Just my two cents. Happy coding 👍

ShortFilmVD
Автор

I’m constantly asked to refactor code I’ve never seen before and I just started my first developer job 2 months ago

JustinLietz
Автор

As James Coplien said as current Dev mantra - we don't need to understand the system, we just need to improve it 😂

Need for velocity tramps common sense, and add a sprinkle of lazyness in thinking things through, we have a recipe for disaster

rommellagera
Автор

Adding third party lib ( cache manager ) makes code slow?

manjunathbm
Автор

A scripting guy talking about refactoring. May be refactor away the whole language. The world will be a better place

jeffepstein
Автор

You know what i do when someone refactors my code and things crash? I revert.

TTBOnbKiLleR