4 ms·
The main purpose of the async/await keywords is to help the programmer reason about what can happen when. Having calls be implicitly parallel makes it difficul
by tveita 11y ago
The main purpose of the async/await keywords is to help the programmer reason about what can happen when.
Having calls be implicitly parallel makes it difficult for the programmer to predict what could be happening elsewhere in the program. E.g., this passage from the Oz documentation[1]:
"Oz 1, supports a fine-grained notion of concurrency where each statement can potentially be executed concurrently. This results in a fine-grained model similar to the actor model. A good exposition of the Oz 1 programming model is given in [Smo95]. Our experience using Oz 1 showed that this kind of model, while theoretically appealing, makes it very hard for the programmer to control the resources of his/her application. It is also very hard to debug programs and the object model becomes unnecessarily awkward."
For I/O in particular it is also difficult for the machine to know what is safe to do in parallel. For instance, two writes to the same file probably has to happen in order. What about writes to different files? What about HTTP requests? Most I/O has the potential to produce wrong results if rearranged in arbitrary order, and requiring the programmer to mark them sequential becomes a potential source of error and a cognitive burden.
In most cases it's better to be slow and correct by default, and allow the programmer to explicitly run things in parallel in the cases it matters.
[1] http://mozart.github.io/mozart-v1/doc-1.4.0/tutorial/node1.html#chapter.introduction http://mozart.github.io/mozart-v1/doc-1.4.0/tutorial/node1.h...
- mhomde 11y agoI agree that those can be issues... but that can be solved by annotating the methods to those constraints. The compiler can even highlight potential problems and ask that you annotate them. The benefit of this approach is that the compiler should be able to see more opportunities for optimization and also result in fewer bugs.