On Tue, Mar 4, 2025, at 23:54, Eugene Sidelnyk wrote: > Hi there, > > I would also like to highlight some interesting ideas that I find being > useful to consider. > > Recently Bend programming language has been released, and it incorporates a > completely different view on the conception of "code", in the definition of > "what it is" and "how it should be interpreted". > > While we interpret it as a sequence of instructions, the proper way of seeing > it is the graph of instructions. On every step we reduce that graph, by > running the code of the nodes current node depends on. > > Therefore, basically everything could paralleled w/o the need to have fancy > management of threads and other low-level things. > > For example, having this code: > > $foo = foo(); > $bar = bar(); > $baz = $foo + $bar; > > If it was run in Bend, it would be interpreted so that foo() and bar() > functions are executed in parallel, and $baz = $foo + $bar is executed > afterwards, since this computation depends on the other two. > > The key, most excellently beautiful feature > here is that all async management is under the hood, exposing nothing for the > developers to be bothered with. > > That being said, I also want to mention that Bend has a primitive for > concurrent loops. Actually, they used another solution, different from loops, > since loops are sequential by their essense (iterative one by one). They > introduced a concurrent alternative for loops with "bend" keyword, allowing > data structures to be traversed in parallel. > > I think this is actually "the right way" of doing parallel processing in > general and async programming in particular, and this is greatly to be > considered for having at least some principles applied in PHP. > > What I think it could be. > > async function baz(): int { > $foo = foo(); > $bar = bar(); > > return $foo + $bar; > } > > // value is returned just like from any other ordinary function > $val = baz(); > > Function above could run foo() in one fiber, and bar() in another, both of > them being awaited at the return statement (at the first statement where the > value is actually used / referenced, if we put it more generally) so that > actual values could be taken. > > In other words, async function is not promise-based as in other languages > that suffer from red blue function problem, but rather it is function with > coroutine flow of execution, so that foo() is executed as the first > coroutine, and when it blocks, then bar() is executed until it also blocks. > Then, at plus operator being evaluated, $foo is awaited, and $bar is awaited, > since they are necessary parts for + operation to complete. > > > Best regards
Huh. Reminds me of SSA, which can identify independent computations like that. It’s used by go, and many other compiled languages, but not in the same way this bend language does it. So, that’s interesting. I don’t know if php could implement SSA (maybe opcache could), but with how dynamic php is, I’m not sure it would be helpful. An interesting application nonetheless, thanks for sharing! — Rob