Funcprog 2022 recap

  • GraphQL API tests with Snowflaqe
  • Functors and Monads as an abstraction
    • ​List<T>
    • Option<T> (Nullable<T>)
    • Result<T, E>
  • Computation expressions
    • async/await
    • error handling
    • any other monad

 

Main "Principles" of Functional Programming

Immutability

Pure functions

C#

  • Immutable data structures
    • Records (without public setters!)
    • Readonly/Immutable collections
    • LINQ
  • Pure functions
    • [Pure] attribute
    • static methods (prevents accessing "this")

Differences between FP and OOP

OOP

Data and operations over data tied together (classes)

FP

Data structures decoupled from operations over data (functions)

Goals of a functional approach

  • Easier to reason about code due to
    • data modelling (type driven approach)
    • immutability (no need to track changes)
    • smaller chunks of code (functions)
    • reliance on (trustworthy) type signatures
    • explicitness (argument passing, no implicit "this")
    • etc
  • Prevent bugs/race conditions due to mutating shared state
  • Compile-time safety
  • Unit testing without mocks (pure functions)

C#: The final missing piece

Made with Slides.com