Technology
Dancing with ZIO
OpenBlend November Meetup
24. 11. 2022We’ll jump into the latest and greatest Scala, check a few fundamental advances and then dance around with ZIO. We’ll look into the core features that elevate what it means to write modern, highly concurrent and resilient, functional, high-performance software.
Talk recap
This talk was automagically recapped with help of Ljubljana.tech Wordsmith AI.
Subjected to paraphrasing and mirror errors.
Subjected to paraphrasing and mirror errors.
- This presentation is on Scala and its latest version, Scala 3. Scala is a programming language that is becoming increasingly popular due to its ability to handle high-performance and concurrent applications. In this presentation, we will explore the features and capabilities of Scala, and discuss why it is gaining popularity among developers.
- Functional programming is a programming paradigm that emphasizes the use of functions to model and solve problems. It is based on the idea that functions should be treated as first-class citizens in the language, and that they should be used to build larger abstractions. There are many benefits to functional programming, including better code readability, easier testing and debugging, and improved maintainability.
- One of the key reasons that Scala is a popular choice for functional programming is its flexibility. Scala allows developers to define functions in many different ways, which makes it easy to scale and build complex abstractions. This is in contrast to languages that have more rigid rules for defining functions, which can make it more difficult to create advanced constructs.
- Another feature of Scala that is worth noting is the concept of currying. Currying is a technique in which a function returns another function. This can be very useful for creating more specialized functions or for implementing higher-order functions that take other functions as arguments.
- In Scala, it is also possible to compose functions. This means that you can take multiple functions and combine them to create a new function. This can be a powerful tool for building complex abstractions, and it is one of the reasons that Scala is such a scalable language.
- Overall, this presentation is designed to be beginner-friendly for those with experience in Java. If you have written Java before, you should feel comfortable with the concepts and syntax presented in this talk. We hope that you will enjoy learning about Scala and that you will see why so many people are now using this technology to build high-performance and concurrent applications.
Audience questions for Oto
These questions were asked by the attending audience of about 80 participants on 24. 11. 2022 at Ljubljana.tech. Maximize your next knowledge experience by attending our event in-person.
- Is there anything fundamentally different from cats with sugar on top? Is there like something radical and new here?
- I made the mistake of asking the author of ZIO about the differences between Cats and ZIO, and it didn't go well. However, I have learned that Cats is a library for functional programming in Scala, while ZIO is a concurrency framework. I think Cats is easier for beginners to use because it doesn't require knowledge of advanced concepts like monads and applicatives. On the other hand, ZIO is faster due to certain features it has. Both frameworks are powerful and useful, but I think ZIO is more "fresh" and user-friendly for those who are new to functional programming. The main difference between the two frameworks seems to be the level of abstraction and the ease of use for those who are not familiar with functional programming concepts.
- Can you gauge the trade off of the benefits you get from using ZIO?
- As a person who has had the opportunity to convince a team to adopt a certain programming framework and choose between different options, I believe that ZIO is much more user-friendly for beginners. It does not require knowledge of advanced concepts like monads and applicatives, unlike other frameworks. In my opinion, ZIO is also more powerful and allows for fast development once the basic concepts are understood. Additionally, many of the concepts demonstrated in ZIO are being replicated in other languages like TypeScript. I think that using a compiled language like Scala, with its powerful compiler and type safety, can help prevent mistakes and improve code quality. However, it is important to be careful and not abuse or use these tools improperly.
- How can I call Scala code from other JVM languages like Java and Kotlin?
- It is possible to use ZIO from Java or Kotlin, as demonstrated in the examples provided. The compiled code can be used as a dependency in a Maven or Gradle project. It is also possible to compile ZIO to JavaScript using ScalaJS, though it will not have the same concurrency features as when running on the JVM. ZIO can also be compiled to run on Grail, which provides additional benefits. It is also possible to use ZIO in the front end to interact with the DOM.
- How can I combine and call code written in Scala and Kotlin from Java, particularly for mission-critical projects?
- I was discussing the concept of exceptions and errors in programming. An exception is an unexpected event that occurs during the execution of a program and can disrupt the normal flow of instructions. Exceptions can be handled within the code or passed to the runtime environment as a cause. I mentioned that it is possible to convert exceptions to causes and vice versa, which allows for fine-grained control over how exceptions are dealt with in the program.
- What about stack traces in ZIO, how does that work?
- In summary, ZIO has a feature called implicit tracing which allows for the tracking of events and exceptions that occur during runtime. The tracing system combines information about the computation and its execution location, and can provide details about the specific line at which a problem occurred. This information can also include details about the fibers being used. This tracking is controlled at runtime and can provide additional context when effects are being executed.
- How would you handle writing an application that uses actors in ZIO?
- The company behind Akka and ZIO is changing their license model, and there are now libraries available that are built on top of ZIO and mimic the actor model, including the use of mailboxes and communication between actors. These libraries can be used to build your own actor model easily, and there are several options to choose from. When designing the architecture of a ZIO application, it is important to consider the use of fibers and how to modularize the application through the use of queues, hubs, and referential maps. The overall goal is to create a well-structured and flat architecture.