3 ms·
>In other words, if async/await is so good, why not make all functions in the language implicitly async, and instead of "await" just write normal function calls
by imtringued 3y ago
>In other words, if async/await is so good, why not make all functions in the language implicitly async, and instead of "await" just write normal function calls? Then you will suddenly be programming in threads.
Why not go one step further and invent "Parallel Rust"? And by parallel I mean it. Just a nice little keyword "parallel {}" where every statement inside the parallel block is executed in parallel, the same way it is done in HDLs. Rust's borrow checker should be able to ensure parallel code is safe. Of course one problem with this strategy is that we don't exactly have processors that are designed to spawn and process micro-threads. You would need to go back all the way to Sun's SPARC architecture for that and then extend it with the concept of a tree based stack so that multiple threads can share the same stack.
- avodonosov 3y agoThat would be a good step forward, I support it :) BTW, do we need the `parallel` keyword, or better to simply let all code be parallel by default?
- josephg 3y agoHaskell has entered the chat… However, almost all of the most popular programming languages are imperative. I assume most programmers prefer to think of our programs as a series of steps which execute in sequence. Mind you, arguably excel is the most popular programming language in use today, and it has exactly this execution model.
- zozbot234 3y ago> Just a nice little keyword "parallel {}" where every statement inside the parallel block is executed in parallel, the same way it is done in HDLs. Rust's borrow checker should be able to ensure parallel code is safe. The rayon crate lets you do something quite similar.
- gpderetta 3y agoYou do not need to spawn threads/tasks eagerly. You can do it lazily on work-stealing. See cilk++.
- galangalalgol 3y agoDoesn't rayon have a syntax like that?
- jerf 3y agoI believe the answer is "that implies a runtime", and Rust as a whole is not willing to pull that up into a language requirement. This is in contrast to Haskell, Go, dynamic scripting languages, and, frankly, nearly every other language on the market. Almost everything has a runtime nowadays, and while each individually may be fine they don't always play well together. It is important that as C rides into the sunset (optimistic and aspirational, sure, but I hope and believe also true) and C++ becomes an ever more complex choice to make for various reasons that we have a high-power very systems-oriented programming language that will make that choice, because someone needs to.
- ngrilly 3y ago> It is important that [...] we have a high-power very systems-oriented programming language that will make that choice, because someone needs to. This is exactly why I'm looking into Zig more.