Divide and conquer complex Javascript logic

preview_player
Показать описание
In "Divide and conquer complex Javascript logic" I showcase an example of how to reduce complexity.

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

Fredrik that was very short and informative. Please do more videos like this one, thanks!

Famouzi
Автор

Very valuable and helpful information. Thank you!

pablomotta___
Автор

Good video, that's a great way of refactoring it. I think the "problem" is that we often create the simplest solution possible in order to meet deadlines and so on. Then the requirements keeps on changing, and people want to add more and more functionality. Eventually you'll end up in a situation where you need to refactor the code. This is where the real problem occurs in my opinion, because large refactorings do not provide immediate value for stakeholders, which is why it's never prioritized, at least not where I work.

One of the projects I work with was basically just one big hacky prototype for the first year of its existence. Then it was decided to just put it into production without any changes, which means that the whole application inherited a terrible foundation that no one has time to rework, because it would basically mean a total rewrite of the application at this point.

WorstDeveloper
Автор

Great video Fred. I'm sure you know in Java, this can be achieved with Polymorphism, specifically the Strategy design pattern which I think is a more elegant way.

StyleTrick
Автор

Great video! Nice and simple explanation. Thanks for this!

I have a curiosity. When we have complex logic, I feel that using if... else... blocks is so hard to read and understand. And sometimes I am thinking of using "switch" instead (where possible, of course). I know technically it is slower than ifs, but, in my opinion, the syntax looks cleaner and it is easier to see what is happening in one glance. Especially if you need to return components, like in your example. What do you think about this approach? Thanks in advance 😎

hamsteroncoffee
Автор

Ah yup dependency injection in a nutshell.
Btw do you follow any of these ports and adapters, Hexagonal Architecture, or clean architecture models at work?
Atm on my personal project which uses GraphQL, I have a /loaders folder to handle stuff like app.use(cookieParser()), and auth where I put /refresh-token, /login-via-google etc (I was thinking if I should create a new folder called routes, but decided against it, cus this is the only routes as of now).
Then I have feature folders like /recipes, and inside that folder I have /services, /schemas, /repositories, and helper functions on the root. I also have a composition root that initialized everything which I pass it down.

To me this seems to be good enough, and I hope it can scale. I recently started reading about architecture patterns by Uncle Bob, etc, it kinda followed their ideas in some way, but they have additional stuff like "use-cases" etc, and I was wondering, should I even bother with that? I can't think of any way how to make my file structures better as of now....

blackdeckbox
join shbcf.ru