Functional Programming in 40 minutes @russolsen Functional - - PowerPoint PPT Presentation

functional programming
SMART_READER_LITE
LIVE PREVIEW

Functional Programming in 40 minutes @russolsen Functional - - PowerPoint PPT Presentation

Functional Programming in 40 minutes @russolsen Functional Programming in 40 minutes @russolsen Functional Programming Functional Programming Clojure spin Functional Programming 40 Minutes? What is it? What's it like? Does it work?


slide-1
SLIDE 1
slide-2
SLIDE 2

Functional Programming

in 40 minutes @russolsen

slide-3
SLIDE 3
slide-4
SLIDE 4
slide-5
SLIDE 5

Functional Programming

in 40 minutes @russolsen

slide-6
SLIDE 6

Functional Programming

slide-7
SLIDE 7

Functional Programming

Clojure spin

slide-8
SLIDE 8

Functional Programming

40 Minutes?

slide-9
SLIDE 9

What is it? What's it like? Does it work?

slide-10
SLIDE 10

What is it? What's it like? Does it work?

slide-11
SLIDE 11

FORGET

Everything You Know About Programming

slide-12
SLIDE 12

What Do You Know?

slide-13
SLIDE 13 Name = Value Names Ifs Iteration Procedures
slide-14
SLIDE 14 Name = Value Names Ifs Iteration Procedures Strings Numerics Booleans Indentation
slide-15
SLIDE 15 Name = Value Names Ifs Iteration Procedures Arrays Hashes Namespaces Strings Numerics Booleans Indentation
slide-16
SLIDE 16 Name = Value Names Ifs Iteration Procedures Classes Inheritance Methods Arrays Hashes Namespaces Strings Numerics Booleans Indentation
slide-17
SLIDE 17 Name = Value Names Ifs Iteration Procedures Classes Inheritance Methods Arrays Hashes Namespaces Programs Strings Numerics Booleans Indentation
slide-18
SLIDE 18

FORGET

Everything You Know About Programming

REALLY?

slide-19
SLIDE 19

Functional Programming

slide-20
SLIDE 20

Everything You Know About Programming

Refactor

slide-21
SLIDE 21
slide-22
SLIDE 22
slide-23
SLIDE 23
slide-24
SLIDE 24
slide-25
SLIDE 25
slide-26
SLIDE 26
slide-27
SLIDE 27
slide-28
SLIDE 28
slide-29
SLIDE 29

It Works But...

slide-30
SLIDE 30

Mess

slide-31
SLIDE 31
slide-32
SLIDE 32
slide-33
SLIDE 33
slide-34
SLIDE 34

What About Programming?

slide-35
SLIDE 35

During the type erasure process, the Java compiler erases all type parameters and replaces each with its first bound if the type parameter is bounded,

  • r Object if the type parameter

is unbounded.

https://docs.oracle.com/javase/tutorial/java/generics/genTypes.html
slide-36
SLIDE 36

During the type erasure process, the Java compiler erases all type parameters and replaces each with its first bound if the type parameter is bounded,

  • r Object if the type

parameter is unbounded.

slide-37
SLIDE 37

Protected methods: a protected method is similar to a private method, with the addition that it can be called with, or without, an explicit receiver, but that receiver is always self (it’s defining class) or an

  • bject that inherits from self .
https://medium.com/@tjoye20/ruby-access-control-basics-public-vs-private-vs-protected- methods-7788b26e04a7
slide-38
SLIDE 38

A friend function of a class is defined

  • utside that class' scope but it has the

right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.

https://www.tutorialspoint.com/cplusplus/cpp_friend_functions.htm
slide-39
SLIDE 39 Name = Value Names Ifs Iteration Procedures Classes Inheritance Methods Arrays Hashes Namespaces Programs Strings Numerics Booleans Indentation
slide-40
SLIDE 40

Messy?

slide-41
SLIDE 41
slide-42
SLIDE 42 Name = Value Names Ifs Iteration Arrays Hashes Namespaces Programs Strings Numerics Booleans Indentation
slide-43
SLIDE 43
slide-44
SLIDE 44
slide-45
SLIDE 45
slide-46
SLIDE 46
slide-47
SLIDE 47
slide-48
SLIDE 48
slide-49
SLIDE 49
slide-50
SLIDE 50

f(x)

slide-51
SLIDE 51

1 2 3 4 5 2 4 6 8 10

f(x)

slide-52
SLIDE 52

1 2 3 4 5 2 4 6 8 10

slide-53
SLIDE 53

Procedures Subroutines Functions Methods

slide-54
SLIDE 54

5 10 3 6

slide-55
SLIDE 55

5 42 3 6 10 ??

slide-56
SLIDE 56

5 10 3 6

slide-57
SLIDE 57

5 10 3 6

slide-58
SLIDE 58

f(x)

A Thing

slide-59
SLIDE 59

f(x)

A Thing I Can Make

slide-60
SLIDE 60

f(x)

slide-61
SLIDE 61

1st Class

slide-62
SLIDE 62

Look at Input Produce Output

slide-63
SLIDE 63

No Side Effects

slide-64
SLIDE 64

x = ['a','b','c'] y = a(x) x = ?

slide-65
SLIDE 65

x = ['a','b','c'] y = x = ?

c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x) - ceil(g(x) - c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x)
slide-66
SLIDE 66 Name = Value Names Ifs Iteration Arrays Hashes Namespaces Programs Strings Numerics Booleans Indentation

f(x)

slide-67
SLIDE 67

Problem

slide-68
SLIDE 68

a b c

slide-69
SLIDE 69

a b c

slide-70
SLIDE 70

a Q c

slide-71
SLIDE 71

x = ['a','b','c'] y = x = ?

c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x) - ceil(g(x) - c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x)
slide-72
SLIDE 72 t = c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x) - ceil(g(x) x[2] = 'Q' y = t + c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x)
slide-73
SLIDE 73 t = c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x) - ceil(g(x)

x[2] = 'Q'

y = t + c(a(x) + b(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + d(x) * e(x) - 4 * (q(x) - f(x)) + b(x)) + d(x) / c(a(x) + b(x)) + d(x) * e(x) + g(x) + h(x) * floor(b(x)) + 16 * a(x)
slide-74
SLIDE 74

Immutable

slide-75
SLIDE 75

a b c a Q c

slide-76
SLIDE 76

Problem

slide-77
SLIDE 77

Copies Copies Copies

slide-78
SLIDE 78 a b c d e f g h i j k l m n
  • p
q r s t u v w x y z !
slide-79
SLIDE 79 a b c d e f g h i j k l m n
  • p
q r s t u v w x y z ! a b c d e f g h i j k l m Q
  • p
q r s t u v w x y z !
slide-80
SLIDE 80

Persistent Data Structures

slide-81
SLIDE 81 a b c d e f g h i j k l m n
  • p
q r s t u v w x y z !
slide-82
SLIDE 82 a b c d e f g h i j k l m n
  • p
q r s t u v w x y z !
slide-83
SLIDE 83 m Q o
slide-84
SLIDE 84 m X
  • Q
slide-85
SLIDE 85 m X
  • Q
slide-86
SLIDE 86 a b c d e f g h i j k l p q r s t u v w x y z ! m X
  • Q
slide-87
SLIDE 87

3

slide-88
SLIDE 88

3

slide-89
SLIDE 89 Name = Value Names Ifs Iteration Arrays* Hashes* Namespaces Programs Strings Numerics Booleans Indentation

f(x)

slide-90
SLIDE 90

Problem

slide-91
SLIDE 91

Side Effects

slide-92
SLIDE 92 Russ Olsen russ@russolsen.com

SIDE EFFECTS

slide-93
SLIDE 93

EFFECTS

Russ Olsen russ@russolsen.com
slide-94
SLIDE 94
slide-95
SLIDE 95

57

Atoms

slide-96
SLIDE 96

57

f(x)

Atoms

slide-97
SLIDE 97

58

f(x)

Atoms

slide-98
SLIDE 98

59

f(x) g(x)

Atoms

slide-99
SLIDE 99

59

f(x) g(x)

Atoms

g(x)

slide-100
SLIDE 100

some_code(queue)

Agents/Actors

f(x) g(x)

slide-101
SLIDE 101 Name = Value Names Ifs Iteration Arrays* Hashes* Namespaces Programs Strings Numerics Booleans Indentation

f(x)

slide-102
SLIDE 102

What is it? What's it like? Does it work?

slide-103
SLIDE 103

Magic

slide-104
SLIDE 104

Magic

slide-105
SLIDE 105

You still have

  • ff-by-one

errors

slide-106
SLIDE 106

You still have REDUNDANT code

slide-107
SLIDE 107

BAD CODE

slide-108
SLIDE 108

The database is

STILL DOWN

slide-109
SLIDE 109

Threads!

slide-110
SLIDE 110
slide-111
SLIDE 111
slide-112
SLIDE 112

What is it? What's it like? Does it work?

slide-113
SLIDE 113

pedestal.io

slide-114
SLIDE 114
slide-115
SLIDE 115

What is Pedestal?

Pedestal is a set of libraries that we use to build services and
  • applications. It runs in the back end and can serve up whole
HTML pages or handle API requests.
slide-116
SLIDE 116

18,706

lines

slide-117
SLIDE 117

28

protocols

+

slide-118
SLIDE 118

8

bridges to the stateful world

slide-119
SLIDE 119

9

Record types

+

slide-120
SLIDE 120

1

multi method

+

slide-121
SLIDE 121

944

functions

f(x)

slide-122
SLIDE 122
slide-123
SLIDE 123 Name = Value Names Ifs Iteration Arrays* Hashes* Namespaces Programs Strings Numerics Booleans Indentation

f(x)

slide-124
SLIDE 124

YES

slide-125
SLIDE 125

Questions?

slide-126
SLIDE 126

@russolsen

slide-127
SLIDE 127
slide-128
SLIDE 128