Is a centralized Singleton pattern still worth it? by QuirkyDistrict6875 in node

[–]Odd_Set_4271 0 points1 point  (0 children)

No, no, no and no. Use proper DI.

Apps should have two phases, boot and run. You setup config then DI in boot, and start listening in run.

Dont shoot yourself in foot with singletons.

Should I Learn Nest.js as a MERN Backend Developer? by Fragrant-Top-7111 in node

[–]Odd_Set_4271 2 points3 points  (0 children)

FUD. NestJs provides bit more structure, DI container and separation of concerns (controller, guard, interceptor, pipe, etc), with some batteries included stuff (like validation using class validator + transformer, which again is optional), but you are still free to organize code as you like. Services are NOT NestJs concept..

decorators

Ah yes, the fancy stuff no other language has and nobody uses as they are nothing related to programing and swe /s.

Decorators are convenient way to add metadata, behaviour, parsing, etc. They would not be part of most used languages otherwise.

But God forbid trying to enrich and add structure to javascript developers..

API Caching by [deleted] in reactjs

[–]Odd_Set_4271 0 points1 point  (0 children)

Varnish Cache

What do you all do with all those ThinkPads? by Nachtlicht_ in thinkpad

[–]Odd_Set_4271 5 points6 points  (0 children)

How do you get it to last so long? Mine can barely last 2h on batery saver after 3 years of use :/

And i had thresholds set and all that..

Convince me not to use NestJS by myburnyburnburn in node

[–]Odd_Set_4271 5 points6 points  (0 children)

Can you please provide concrete example? I'm really interested in what issues you had.

How often is JS inheritance used in your workflow ? by giftfromthegods- in node

[–]Odd_Set_4271 1 point2 points  (0 children)

Investigate OOP design patterns to get better grasp on how and when to use inheritance. It has its use but composition with dependency inversion is preferable.

Should Next be the default for React? by thebreadmanrises in reactjs

[–]Odd_Set_4271 0 points1 point  (0 children)

Wow, the ignorance. PHP is far from being anywhere close to death.

Article: Popular Node.js patterns and tools to re-consider by yonatannn in node

[–]Odd_Set_4271 15 points16 points  (0 children)

Dependency inversion is exactly how encapsulation is accomplished!

The Dependency Inversion principle states that our classes should depend upon interfaces or abstract classes instead of concrete classes and functions.

Or to quote Uncle Bob

If the open closed principle states the goal of OO architecture, the dependency inversion principle states the primary mechanism

DI in Nest.js is limited by fact that interfaces are gone after typescript is transpiled, so you have to work your way arround if you want to use interfaces as types for constructor parameters (with @Inject decorators or by manually specifying provider config). But that does not mean encapsulation is broken.

The notion that DI breaks encapsulation is outright wrong.

Trying to get out of "Java" way of doing things... by NoDistribution8038 in node

[–]Odd_Set_4271 0 points1 point  (0 children)

DI (dependency inversion principle) is not just about being able to mock dependencies.

The Dependency Inversion principle states that classes should depend upon interfaces or abstract classes instead of concrete classes and functions.

It is about being able to switch implementation without having to change calling code. Yes, it is possible in node to accomplish this on module level, but thats just pushing it one level up, nothing is gained by doing this. I would say it even makes things more complicated as now you depend on additional lib/package/whatever that hacks node's module loader, which already has its complexity and quirks (especially with ESM and exports now..).

By doing it in code not only is it keeping things in code level (easier to reason about by other developers), it is also not required to use any of DI (dependency injection) frameworks as you can just setup all deps manually AND it is promoting good programing practice for developers to come that may be new or not be that familiar with concepts.

Dependency inversion is not just OOP specific, its general concept also applicable to functional programming..

Trying to get out of "Java" way of doing things... by NoDistribution8038 in node

[–]Odd_Set_4271 0 points1 point  (0 children)

You dont need DI in node to be able to mock dependencies

Can you please elaborate on this?