Yejun Su
January 03, 2023
110

# Functional programming - part 1

Learning the skill "Distinguish Actions, Calculations and Data".

January 03, 2023

## Transcript

1. ### Functional programming James Su - 2022/04/15 Sur f ing in

the changing world

3. ### Functional programming in Wikipedia • A programming paradigm characterized by

mathematical functions and the avoidance of side e ff ects. • A programming style that uses only pure functions without side e ff ects.

value
5. ### Pure functions Don't have any side e ff ects. Given

the same arguments, return the same result.
6. ### Bene f its of pure functions • Don't depend on

how many times and when they are run. • Results are predictable, easier to understand and control. • Compilers can optimize for predictable things.
7. ### But, we need side effects in real world • Send

an email • Reading a f ile • Writing to database • Making a web request • Blinking a light
8. ### Functional programming in real world • A set of skills,

concepts and principles: • Distinguishing actions, calculations, and data • Staying immutable in a mutable language • ... and more • They are valuable and regardless of what language you use.

10. ### Actions • Depend on how many times or when it

is run. • Also called: functions with side e ff ects. • Examples: • Send an email • Read from a database
11. ### Calculations • Computations from input to output. • Also called:

pure functions, mathematical functions. • Examples: • Find the users to send email • Calculate total price in shopping cart
12. ### Data • Facts about events. • Their meanings are di

ff erent according to situations. • Examples: • An email address • A user structure • A dinner receipt
13. ### Bene f its of distinguishing actions, calculations and data •

Thinking about a problem • Clarify parts that need special attention (actions) • What data we will need to capture (data) • What decisions we will need to make (calculations) • Coding a solution • Write code with immutable in mind: data > calculations > actions. • Reading code • Refactor the code to better separate from actions, calculations and data.

18. ### Functional languages • Erlang • WhatsApp - Why WhatsApp Only

Needs 50 Engineers for Its 900M Users • Elixir • Discord - How Discord Scaled Elixir to 5,000,000 Concurrent Users • Apple - Working on APIs towards carbon neutral by 2030 • Clojure • Roam Research - State of Clojure 2021 Results • Elm • https://github.com/jah2488/elm-companies • Blazing Fast HTML
19. ### We are in a world programs run on multicores and

distributed devices • Functional programs run in parallel. • Compilers optimize for functional programs.