News for hackers. Stuff that matters.
Re:.NET 5.0 by davidfowl on Tuesday November 10, 2020 @04:07PM (#25051920)
I can get behind the DI dislike, but how are callbacks and promises in nodejs better than async in .NET?
Re:.NET 5.0 by Xeronate on Tuesday November 10, 2020 @04:55PM (#25052519)
What’s not to like about DI? Makes it so much easier to wire up dependent services and refactor those wirings at a later time. If you don’t use DI you have to manually manage everything yourself.
Re:.NET 5.0 by charlieflowers on Tuesday November 10, 2020 @11:38PM (#25055533)
If you go too far with DI, the saying is "everything happens somewhere else."

Some feel it can be needlessly complex to troubleshoot such a system or gain understanding of it if you weren't one of the original authors.

Re:.NET 5.0 by Xeronate on Wednesday November 11, 2020 @02:25AM (#25056231)
Don't need DI to make your program so abstract no one can follow it. Wouldn't even say DI makes it easier to do because you can accomplish the same thing by just newing up objects.
Re:.NET 5.0 by WorldMaker on Wednesday November 11, 2020 @01:05PM (#25060923)
That's related to my rule of when DI is being abused: if you can't just new up the objects by hand (perhaps in a unit test somewhere), then you should rethink your use of DI.

I've seen projects where the dependency object graph exceeded anything you could possibly new up yourself, due to circular dependencies and impossibly complex scope rules. That's definitely a sign of a program so abstract no one can follow it.

(Microsoft's very simple DI container that's now standard out-of-the-box in .NET Core has somewhat strict limits on DI scopes and disallows circular dependencies, so it's one of the better ones.)

Re:.NET 5.0 by vosper on Tuesday November 10, 2020 @04:17PM (#25052049)
If you're writing modern nodeJS you're probably not using callbacks or promises (directly) anymore (or using promises a lot less than you used to - Promise.all and Promise.allSettled is about it for me, and that's not that often).

The async/await syntax is where it's at. Honestly it's a massive improvement over promises, which I hated reasoning about almost as much as callbacks :)

Re:.NET 5.0 by charlieflowers on Tuesday November 10, 2020 @05:18PM (#25052808)
And ... C# _invented_ the async/await syntax. Node, Rust, etc., were all inspired by what C# did.
Re:.NET 5.0 by dragonwriter on Tuesday November 10, 2020 @05:23PM (#25052884)
> If you're writing modern nodeJS you're probably not using callbacks or promises (directly) anymore

I get that some people prefer async/await (I actually find explicit Promises clear enough that I don't have any strong preference, myself), but why wouldn't you be using explicit callbacks, which in my JS experience (mostly frontend, but also fairly modern) are super common outside of promises, which is the only place where I see modern JS replacing exlicit callbacks with a different structure.

Re:.NET 5.0 by vosper on Tuesday November 10, 2020 @09:04PM (#25054779)
Yeah, callbacks are fine until you get a big stack of them (so-called “callback hell”). Promises were the touted solution to callback hell, async/await the touted solution to endless promises chaining. While async/await is (tasty) syntactic sugar for promises, I think it’s a real improvement over callbacks - it’s one less argument to every function (because of promises) and I think it’s easier to read: there tends to be less nesting.
Re:.NET 5.0 by dragonwriter on Wednesday November 11, 2020 @03:44AM (#25056645)
The weird thing about async/await is that it gets you out of deeply nested callbacks into, pretty much by definition, exactly equally deeply nested async function calls. The only thing that seems different is that it seems to be more common (but not any more or less supported, since you can obviously have named non-async functions and you can also have anonymous async functions) to call named functions in async/await and anonymous functions defined inline as callbacks with promises.