Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Functional Programming for Fun and Profit!!

Jenny Shih
November 18, 2022

Functional Programming for Fun and Profit!!

Presented at RubyConf Mini 2022

Jenny Shih

November 18, 2022
Tweet

More Decks by Jenny Shih

Other Decks in Technology

Transcript

  1. @jenny_codes An OO program Object Value Behavior Object Value Behavior

    Object Value Behavior Time Time Time Time Time Time
  2. @jenny_codes Immutability: How??? • Provide a good reason for every

    value mutation. • Use tools • `dry-struct`: https://dry-rb.org/gems/dry-struct/main/
  3. @jenny_codes Immutability: How??? • Provide a good reason for every

    value mutation. • Use tools • `dry-struct`: https://dry-rb.org/gems/dry-struct/main/ • `Data.de fi ne` in Ruby
  4. @jenny_codes Immutability: How??? • Provide a good reason for every

    value mutation. • Use tools • `dry-struct`: https://dry-rb.org/gems/dry-struct/main/ • `Data.de fi ne` in Ruby
  5. @jenny_codes 1. Only depends on its input argument 2. Does

    not mutate states (no side effects) A pure function
  6. @jenny_codes 1. Only depends on its input argument 2. Does

    not mutate states (no side effects) A pure function
  7. @jenny_codes 1. Only depends on its input argument 2. Does

    not mutate states (no side effects) A pure function
  8. @jenny_codes 1. Only depends on its input argument 2. Does

    not mutate states (no side effects) A pure function
  9. @jenny_codes 1. Only depends on its input argument 2. Does

    not mutate states (no side effects) A pure function
  10. @jenny_codes 1. Only depends on its input argument 2. Does

    not mutate states (no side effects) A pure function
  11. @jenny_codes 1. Only depends on its input argument 2. Does

    not mutate states (no side effects) A pure function
  12. @jenny_codes 1. Only depends on its input argument 2. Does

    not mutate states (no side effects) A pure function
  13. @jenny_codes 1. Only depends on its input argument 2. Does

    not mutate states (no side effects) A pure function
  14. @jenny_codes “The problem with OO languages is they’ve got all

    this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.” – Joe Armstrong, Creator of Erlang Pure functions: Why??
  15. @jenny_codes “The problem with OO languages is they’ve got all

    this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.” – Joe Armstrong, Creator of Erlang Pure functions: Why??
  16. @jenny_codes Pure functions: Why?? No implicit environment!! 🤘🐛 🔪 🧪

    ✅ ✌ Source: https://www.ktiv.com/2022/10/07/nobel-peace-prize-awarded-human-rights-advocates/
  17. @jenny_codes 1. Only depends on its input argument 2. Does

    not mutate states (no side effects) A pure function
  18. @jenny_codes A pure function 1. Only depends on its input

    argument ✅ 2. Does not mutate states (no side effects)
  19. @jenny_codes A pure function 1. Only depends on its input

    argument ✅ 2. Does not mutate states ✅ (no side effects)
  20. @jenny_codes An OO program Object Value Behavior Object Value Behavior

    Object Value Behavior Time Time Time Time Time Time
  21. @jenny_codes An OO program Object Value Behavior Object Value Behavior

    Object Value Behavior Time Time Time Time Time Time Global Interpreter Lock 🔐
  22. @jenny_codes “It’s multi-core age today. Concurrency is very important. With

    Ractor, along with Async Fiber, Ruby will be a real concurrent language.” — Matz Ruby’s concurrency abstraction: Ractor https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/
  23. @jenny_codes Ractor Ractor Ractor 🔐 🔐 🔐 ︴︴︴ ︴︴︴ ︴︴︴

    🔐 = Global Interpreter Lock Ruby’s concurrency abstraction: Ractor ︴︴︴= threads
  24. @jenny_codes Ractor Ractor Ractor 🔐 🔐 🔐 ︴︴︴ ︴︴︴ ︴︴︴

    🔐 = Global Interpretation Lock Ruby’s concurrency abstraction: Ractor ︴︴︴= threads ❓
  25. @jenny_codes We are defined not so much by what we

    can do, but what we don’t do.
  26. @jenny_codes Resources: Functional programming mental model • Jose Valim’s ElixirConf

    2017 Keynote by Jose Valim • Are we there yet by Rich Hickey • The language of programming by Anjana Vakil • Value Object by Martin Fowler
  27. @jenny_codes Resources: Functional programming architecture (That I didn’t get to

    talk about because I’d get too excited and run overtime) • Functional Architecture for the Practical Rubyist by Tim Riley • Functional web with Ruby by Luca Luigi • Boundaries by Gary Bernhardt • The Hanami Ruby framework • (Book) Domain Modelling Made Functional by Scott Wlaschin