functional programming - goto conference...protected methods: a protected method is similar to a...

Post on 23-May-2020

2 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Functional Programmingin 40 minutes

@russolsen

Functional Programmingin 40 minutes

@russolsen

Functional Programming

Functional ProgrammingClojure spin

Functional Programming40 Minutes?

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

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

FORGET Everything You Know About Programming

What Do You Know?

Name = ValueNames Ifs Iteration Procedures

Name = ValueNames Ifs Iteration Procedures

Strings Numerics Booleans Indentation

Name = ValueNames Ifs Iteration Procedures

Arrays HashesNamespaces

Strings Numerics Booleans Indentation

Name = ValueNames Ifs Iteration Procedures

Classes Inheritance Methods

Arrays HashesNamespaces

Strings Numerics Booleans Indentation

Name = ValueNames Ifs Iteration Procedures

Classes Inheritance Methods

Arrays HashesNamespaces

Programs

Strings Numerics Booleans Indentation

FORGET Everything You Know About ProgrammingREALLY?

Functional Programming

Everything You Know About Programming

Refactor

It Works But...

Mess

What About Programming?

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, or Object if the type parameter is unbounded.

https://docs.oracle.com/javase/tutorial/java/generics/genTypes.html

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,

or Object if the type parameter

is unbounded.

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 object that inherits from self .

https://medium.com/@tjoye20/ruby-access-control-basics-public-vs-private-vs-protected-methods-7788b26e04a7

A friend function of a class is defined outside 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

Name = ValueNames Ifs Iteration Procedures

Classes Inheritance Methods

Arrays HashesNamespaces

Programs

Strings Numerics Booleans Indentation

Messy?

Name = ValueNames Ifs Iteration

Arrays HashesNamespaces

Programs

Strings Numerics Booleans Indentation

f(x)

1

23

4

5

2

46 8

10

f(x)

1

23

4

5

2

46 8

10

Procedures

Subroutines

Functions

Methods

5 10

3 6

5 42

3 6

10 ??

5 10

36

5 10

3 6

f(x)A Thing

f(x)A Thing I Can Make

f(x)

1st Class

Look at Input

Produce Output

No Side Effects

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

y = a(x)

x = ?

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)

Name = ValueNames Ifs Iteration

Arrays HashesNamespaces

Programs

Strings Numerics Booleans Indentation

f(x)

Problem

a b c

a b c

a Q c

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)

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)

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)

Immutable

a b c

a Q c

Problem

Copies Copies Copies

a b c d e f g h i j k l m n o p q r s t u v w x y z !

a b c d e f g h i j k l m n o 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 o p q r s t u v w x y z !

Persistent Data Structures

a b c d e f g h i j k l m n o p q r s t u v w x y z !

a b c d e f g h i j k l m n o p q r s t u v w x y z !

m Q o

m X oQ

m X oQ

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 oQ

3

3

Name = ValueNames Ifs Iteration

Arrays* Hashes*Namespaces

Programs

Strings Numerics Booleans Indentation

f(x)

Problem

Side Effects

Russ Olsenruss@russolsen.com

SIDE EFFECTS

EFFECTSRuss Olsenruss@russolsen.com

57Atoms

57f(x)

Atoms

58f(x)

Atoms

59f(x)

g(x)

Atoms

59f(x)

g(x)

Atoms

g(x)

some_code(queue)

Agents/Actors

f(x)

g(x)

Name = ValueNames Ifs Iteration

Arrays* Hashes*Namespaces

Programs

Strings Numerics Booleans Indentation

f(x)

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

Magic

Magic

You still have off-by-one errors

You still have REDUNDANT code

BAD CODE

The database is STILL DOWN

Threads!

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

pedestal.io

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.

18,706lines

28protocols

+

8bridges to the stateful world

9Record types

+

1multi method

+

944functions

f(x)

Name = ValueNames Ifs Iteration

Arrays* Hashes*Namespaces

Programs

Strings Numerics Booleans Indentation

f(x)

YES

Questions?

@russolsen

top related