Effect Oriented Programming

Bruce Eckel

Author/Consultant MindViewLLC.com

Bill Frasure

Developer

James Ward

Developer Advocate @ AWS


https://effectorientedprogramming.github.io/presos/dev2next_2024

(From a Rory Sutherland TED talk)

  • Food Rating: 8.5/10
  • Food Rating: 8.5/10
  • Restaurant goal: 9/10
What Problem are we Solving?
Building Blocks => Composability
f(g(h()))

A sentence is composed of words.

A sentence is composed of words.

f(g(h()))
 f( g( h()))
Cool
Cool
Cool
Remind me why we would do this?

What Impedes Composability?

def p(a: Int, b: Int): Int =
  a + b
  • No Surprises/Unpredictabilities
  • Results can be cached
  • Pure function
  • Because there are no Surprises: Easily Composed
def u(a: Int, b: Int): Int =
  a + b + scala.util.Random.nextInt()
  • Unpredictable, No Longer Pure
  • The Surprises Make it Hard to Test & Compose

Even the Simplest Functions can Produce Surprises

def divide(a: Int, b: Int): Int =
  a / b

Surprises/Unpredictabilies == Side Effects

Effect System

  • Side Effects ==> Managed Effects
  • Shortened to just Effects
  • def c(a: Int, b: Int): Result =
      a + b + ControlledRandom.nextInt()
    

    To Keep This From Happening To Me (Again)

    • Bill & James abstracted away the underlying machinery—including much of Scala
    • If you're a purist this might make you mad
    • We're going to risk it—we think you can "program without first understanding the compiler"