Coder Social home page Coder Social logo

tassiluca / direct-style-experiments Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 2.0 14.83 MB

Analysis of direct style (for asynchronous reactive programming) in Scala

Home Page: https://tassiluca.github.io/direct-style-experiments/

Scala 75.90% Kotlin 24.10%
asynchronous-programming direct-style

direct-style-experiments's Introduction

Analysis of direct style (for asynchronous reactive programming) in Scala

Context

In the realm of asynchronous programming, the Scala ecosystem offers a set of solid and widely adopted monadic constructs and libraries to tackle complex tasks functionally with elegance and efficiency, like Monix Tasks and Cats Effecs, enabling a wide range of interesting and useful features, like composable error handling, cancellation mechanisms and structured concurrency that the standard library lacks. However, they also come with a cost: the pervasiveness of the flatMap operator to compose values makes the code harder to reason about and difficult and awkward to integrate with regular control structures.

In the last years, we have been assisting the increase in adoption of continuations and coroutines in modern runtimes, either exploiting some kind of fiber support, like the project Loom with Virtual Threads, or via code generation, like Kotlin Coroutines. Even Scala is not immune to this trend and a new strawman library, Gears, is currently being developed, aiming to bring direct style support for asynchronous programming. Despite the interest and the potential this new library could bring, it is just a speck that fits into a bigger picture, which is the management of effects: the ongoing research activity led by M. Odersky has indeed the goal to, instead of pushing effect management into external libraries, upgrade the type system to handle effects natively using capabilities, as research-oriented programming languages do with Algebraic Effects (like Koka).

Goals

The goal of this project is to explore, mainly focusing on Scala, the direct style, developing a few examples (not too complex) leveraging the new strawman library Gears for asynchronous programming, comparing it with Kotlin Coroutines and the current implementation of monadic Futures, seeking to analyze aspects such as:

  • ergonomics of the two styles;
  • which of the two approaches has a real advantage in adoption;
  • pros and cons of the two styles;
  • any limitations and difficulties encountered in using them.

Overview

The project is built around three main examples, delving from the fundamentals of the direct style frameworks for simple asynchronous computation to more complex reactive-like systems. The full discussion of these examples can be found in the documentation.

Code has been organized in Gradle submodules, one for each version of the examples (current monadic futures, Scala Gears, Kotlin Coroutines). Here an overview of the project folder structure:

direct-style-experiments
├── analyzer-commons         # common code for analyzers (UI, controller, ...)
├── analyzer-direct          # analyzer example using Scala Gears
├── analyzer-direct-kt       # analyzer example using Kotlin Coroutines
├── analyzer-monadic         # analyzer example using current Futures
├── blog-ws-commons          # common code for the blog service example
├── blog-ws-direct           # blog service example using Scala Gears
├── blog-ws-direct-kt        # blog service example using Kotlin Coroutines
├── blog-ws-monadic          # blog service example using current Futures
├── commons/                 # modules with common code for entire project
│   ├─ src/
│   │  └─ main/
│   │     └─ scala/
│   │        ├─ boundaries   # `boundary` and `break` implementations
│   │        ├─ examples     # some examples
│   │        └─ pimping      # proposed extensions to the Scala Gears library
│   └─ test                  # general tests (cancellation, structured concurrency, ...)
├── rears                    # extensions to the Scala Gears library for Rx
├── smart-hub-direct         # smart hub example using Scala Gears
└── smart-hub-direct-kt      # smart hub example using Kotlin Coroutines

⚠️ Examples works with a version of the JDK > 21 (Virtual Threads are needed!).

To build and run all the tests:

./gradlew build

Generally speaking, the runnable examples can be run by simply executing the run Gradle task in the respective submodule, like:

./gradlew :analyzer-direct:run

Detailed instructions can be found in the README file of each submodule and in the documentation.

direct-style-experiments's People

Contributors

tassiluca avatar renovate[bot] avatar danysk avatar

Stargazers

Davide Domini avatar Kelvin Olaiya avatar Andrea Giulianelli avatar Karl F Walkow avatar Nicolas Farabegoli avatar Gianluca Aguzzi avatar

Watchers

Lucian avatar  avatar

direct-style-experiments's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency scalafmt to v3.8.3
  • chore(deps): update kotlin to v1.9.25 (org.jetbrains.kotlin.plugin.serialization, org.jetbrains.kotlin.jvm)
  • fix(deps): update dependency org.jetbrains.kotlin:kotlin-stdlib to v1.9.25
  • fix(deps): update dependency org.jetbrains.kotlinx:kotlinx-serialization-json to v1.7.1
  • fix(deps): update dependency org.mockito:mockito-core to v5.12.0
  • fix(deps): update dependency org.typelevel:cats-core_3 to v2.12.0
  • fix(deps): update kotest to v5.9.1 (io.kotest:kotest-runner-junit5-jvm, io.kotest:kotest-assertions-core-jvm)
  • fix(deps): update retrofit monorepo to v2.11.0 (com.squareup.retrofit2:adapter-rxjava, com.squareup.retrofit2:retrofit-mock, com.squareup.retrofit2:retrofit)
  • chore(deps): update kotlin to v2 (major) (org.jetbrains.kotlin.plugin.serialization, org.jetbrains.kotlin.jvm)
  • chore(deps): update plugin multijvmtesting to v1
  • fix(deps): update dependency org.jetbrains.kotlin:kotlin-stdlib to v2
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/build-test.yaml
  • actions/checkout v4
  • actions/setup-java v4
.github/workflows/publish-doc.yaml
  • DanySK/compile-and-publish-all-latex 2.0.28
  • danysk/action-checkout 0.2.14
  • gohugoio/hugo v0.124.1
  • peaceiris/actions-gh-pages v3
gomod
docs/site/go.mod
  • go 1.21
gradle
settings.gradle.kts
  • org.danilopianini.gradle-pre-commit-git-hooks 2.0.4
build.gradle.kts
analyzer-commons/build.gradle.kts
analyzer-direct/build.gradle.kts
analyzer-direct-kt/build.gradle.kts
analyzer-monadic/build.gradle.kts
blog-ws-commons/build.gradle.kts
blog-ws-direct/build.gradle.kts
blog-ws-monadic/build.gradle.kts
commons/build.gradle.kts
gradle/libs.versions.toml
  • org.scala-lang:scala3-library_3 3.4.0
  • io.monix:monix_3 3.4.1
  • com.softwaremill.sttp.client3:core_3 3.9.7
  • com.softwaremill.sttp.client3:upickle_3 3.9.7
  • com.softwaremill.sttp.client3:async-http-client-backend-monix_3 3.9.7
  • org.typelevel:cats-core_3 2.10.0
  • org.scalatest:scalatest_3 3.2.17
  • com.vladsch.flexmark:flexmark-all 0.64.8
  • eu.monniot:scala3mock_3 0.6.0
  • eu.monniot:scala3mock-scalatest_3 0.6.0
  • org.jetbrains.kotlin:kotlin-stdlib 1.9.24
  • io.kotest:kotest-assertions-core-jvm 5.8.1
  • org.jetbrains.kotlinx:kotlinx-coroutines-core 1.8.0
  • org.jetbrains.kotlinx:kotlinx-coroutines-swing 1.8.0
  • com.squareup.okhttp3:okhttp 4.12.0
  • com.squareup.retrofit2:retrofit 2.10.0
  • com.squareup.retrofit2:retrofit-mock 2.10.0
  • com.squareup.retrofit2:adapter-rxjava 2.10.0
  • com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter 1.0.0
  • org.jetbrains.kotlinx:kotlinx-serialization-json 1.6.3
  • io.kotest:kotest-runner-junit5-jvm 5.8.1
  • org.mockito:mockito-core 5.11.0
  • com.github.maiflai.scalatest 0.32
  • org.danilopianini.multi-jvm-test-plugin 0.5.8
  • org.jetbrains.dokka 1.9.20
  • org.jetbrains.kotlin.jvm 1.9.24
  • org.jetbrains.kotlin.plugin.serialization 1.9.24
  • org.danilopianini.gradle-kotlin-qa 0.61.0
  • com.github.johnrengelman.shadow 8.1.1
rears/build.gradle.kts
smart-hub-direct/build.gradle.kts
smart-hub-direct-kt/build.gradle.kts
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.7
scalafmt
.scalafmt.conf
  • scalafmt 3.8.2

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.