proposal: async mode #3735
Replies: 5 comments
-
If nothing else, this would create a dialect of C# (since you've have a change in syntax based on some switch), which the LDM team is against. |
Beta Was this translation helpful? Give feedback.
-
For better or worse, Some other points to consider:
|
Beta Was this translation helpful? Give feedback.
-
valid points all. I guess though, I'm finding that I sort of have sync libraries and async libraries - and in the async libraries, essentially everything is async. I code as functionally as possible - all immutable objects etc - and normally the thing at the bottom of the tree is the async bit, so the entire tree ends up being async. my average function length is 1.4 lines, so between them the words "Task" and "async" actually form a significant percentage of the entire codebase :( |
Beta Was this translation helpful? Give feedback.
-
... No Task.FromResult is a syncronous api. I don't agree with you're code since code and you're idea for two reason. Async is done for performance it can bring a lot of bug and complexity to debug. With you're solution we cannot control anythinks.
And on you're final code you're write
I'm not sure but my theorie is that you don't have understand what is a task and you added
And on you're final code you're write
Yes and no. For long operation or web and UI you have async for anythinks else isnt'. Async does 'pollute' you're caller but does not polute the method you call... Async is slower than normal method call because the return must be encapsulated inside a Task... (CF. https://devblogs.microsoft.com/dotnet/understanding-the-whys-whats-and-whens-of-valuetask/ , https://devblogs.microsoft.com/dotnet/async-valuetask-pooling-in-net-5/)
Why would you remove await. And what if i want to start multiple task and wait them later. It's a big lost just to earn one keyword in the code. |
Beta Was this translation helpful? Give feedback.
-
I like the idea a lot (in fact I got to it because I thought about something similar myself). With that said, I also get the objections regarding creating a new dialect of C#. In addition, I'd like to point another problem with the way things currently work: often when you start creating something simple you can get pretty well with synchronous code, but then if at some point you realize that you need to change the implementation to be asynchronous, it means that you must change your API and break backward compatibility. This is especially relevant to interfaces which can have different implementations, where the simpler one can provide information directly from memory (synchronous) and more complex ones provide the same information from disk or over the network (async). To make this point even stronger, when you do TDD, as you typically start with the simplest case (sync) and then gradually grow and refactor. But because of the impedance mismatch between sync and async, the refactoring is becomes too complex and also requires to break the interfaces. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
this is suggestion that may leave you convinced of my lack of sanity - but I'm actually serious - I'd love this.
Essentially a mode, at the project level (like nullable) - that says "everything is async".
Because bottom line - once you start going async, you sort of have to have most stuff async anyway, and it becomes "work" to decide at each point. More than that - the syntax is very heavy. And of course, it's completely trivial to turn any "sync" call into an async function with Task.FromResult - so the idea would be - you turn on async at the project level - and instead of writing:
you could just write:
which would be completely equivalent to the previous one. You'd probably still need "await" - (although I reckon even that could disappear, as the compiler could see whether you later passed the result to something that took a task explicitly - I think it would be valid to assume that any invocation should be awaited before use if and only if you don't pass the result to some helper function that does things with tasks (and you could make a DontAwait helper :))). - and you could definitely know for sure (with some ide support) if someone called properties that exist on the result - as opposed to the Task<?> - then you know they meant it to be awaited.
Anyway - the point is - at the moment there's quite a big impedance mismatch between the sync and async world - it would collapse to a much simpler picture if we just had a project where every function was intrinsically async, without all the noise of "async" and "task" that normally come with it.
For really cool extra points, you could also implicitly pass a cancellation token to every method - and check it at the start of the method, and inside any loops - because even people who have fully embraced async often don't bother plumbing through cancellation.
And while 1.0 would be just a naive rewrite - you could almost do it at the code level with roslyn - or hey... generators... - if people bought into the concept, there's obviously massive potential to optimise a lot of the overhead out automatically.
Beta Was this translation helpful? Give feedback.
All reactions