Beyond Loom

Eric Kolotyluk eric at kolotyluk.net
Thu Feb 15 18:04:47 UTC 2024


Exactly, Java is not a research language, which is why taming Delimited 
Continuations with Virtual Threads was a nice solution to the pain of 
Delimited Continuation in Scala.

Also, Loom took away the pain of Functional Reactive Programming. I was 
sold on FRP for a while, but it's obviously easier to write more 
readable/maintainable code in Loom. My experiments with Loom convince me 
it is just as performant as FRP, but a lot more readable and 
comprehensible.

I am not suggesting Java implement Effects, Effect Handlers, Resource 
Management, etc.; I am saying I am curious what the next great insight 
will be, like Loom. But, until inspiration hits someone, I have to be 
patient.

FS2, Cats Effect, Zio,... are all interesting, but are still hard to 
read, the cognitive load too high, the knowledge investment steep. My 
first attempt at FS2 was to add error handling to their introductory 
example.

import cats.effect.{IO, IOApp}
import fs2.{Stream, text}
import fs2.io.file.{Files, Path}

import scala.util.{Failure, Success, Try}

object Converterextends IOApp.Simple {

   private val converter: Stream[IO, Unit] = {
     def fahrenheitToCelsius(f: Double) =
       (f -32.0) * (5.0/9.0)

     Files[IO].readUtf8Lines(Path("testdata/fahrenheit.txt"))
       .filter(s => s.trim.nonEmpty && !s.startsWith("//"))
       .map(line => Try {line.toDouble}match case Success(value) => fahrenheitToCelsius(value).toString
         case Failure(cause) =>s"Failed to convert $line: $cause" )
       .intersperse("\n")
       .through(text.utf8.encode)
       .through(Files[IO].writeAll(Path("testdata/celsius.txt")))
   }

   def run: IO[Unit] =
     converter.compile.drain
}

Which is not bad for reading, but still too esoteric, especially for 
someone on-boarding. It took me a long time to find this solution, 
because the normal FS2 error handling is to just throw the baby out with 
the bathwater. While I understand this code, I would not recommend this 
to most people, unless they are doing something highly specialized.

I have yet to implement the paralleled/concurrent version of this, 
because I cannot imagine how, yet. However, I could pretty quickly write 
the Loom equivalent. We should not be writing code that requires a PhD 
to read and maintain. The goal should not be to minimize the number of 
lines in the source file, but to maximize the clarity of the code, the 
problem being solved, such that more people can reason about clearly.

All I am saying is I really appreciate Loom... please keep doing what 
you are doing.

Cheers, Eric


On 2024-02-15 9:14 a.m., Ron Pressler wrote:
> Unlike some other languages, Java is not a research language, and this means that we’re not typically looking for cool solutions or even for interesting problems to solve. Rather, we have many millions of developers, and we try to identify the problems that cause the most pain when integrated over all our users, and then we look for a solution.
>
> So when we identify a painful problem that could be solved by the technology contributed by Project Loom (maybe the difficulty of writing “dynamic" iterators/stream which is perhaps best addressed by generators), then we’ll know what the next use of the technology is. BTW, I’ve been following effect systems for over a decade and, AFAIK, to date no one has identified a big problem that is best solved by them.
>
>
> — Ron
>
>> On 15 Feb 2024, at 05:31, Eric Kolotyluk<eric at kolotyluk.net>  wrote:
>>
>> Years ago I tried playing with 'Delimited Continuations' in Scala.
>> I seriously hurt my brain. 😱
>> Eventually, some yahoos implemented Delimited Continuations in Loom, and life was better. 🥳
>> I really enjoy Virtual Threads and Structured Concurrency, but now I wonder what is next. 🤔
>> I can program in Scala and Kotlin just fine, but there is a high cognitive load sometimes... I am always looking to Java where my brain can relax, where it's Five O'Clock Somewhere. 😎
>> I have been looking at 'Effects Systems' a lot, but there is still a lot to learn. 😳
>> Probably one of the best videos I have seen is Effect Systems in Scala: An introduction.
>> While I have been playing with FS2, I really want to wrap my brain around Algebraic Effects, and I am wonder where Caprese is going? Cats Effect and Zio look interesting, and necessary for FS2, but neither seem to be based on Algebraic Effect as explained in DIRECT STYLE SCALA.
>> I am not telling the Loomers what to do, I and just speculating on where they go after Loom. 🧐
>> I also found Haskell'23] The Evolution of Effects very satisfying, as a way to update my dormancy in Computing Science in recent years.
>> Java Streams are a big disappointment, in that we should be able to hang those methods off the collections directly, so they are not lazy... the way Scala separates Collections from Views. Sometimes you don't want the overhead of a Stream, as I discovered play with Loom. Not a biggie, just a gotcha. Maybe with Effects and Resources, we cannot do that?
>> But, those Java Architects, they sure seem good at paying attention to future proofing Java, and on a six month release cycle, it is really entertaining, and useful to see what they come up with next...
>> Cheers, Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20240215/fb915f04/attachment-0001.htm>


More information about the loom-dev mailing list