why isn’t functional programming the norm? · clojure reasonml potential fp killer apps elm-ui...

79
Why isn’t Functional Programming the Norm? @rtfeldman

Upload: others

Post on 05-Jul-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Why isn’t Functional Programming the Norm?

@rtfeldman

Page 2: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Why are thingsthe way they are?

Page 3: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

It’s complicated!

Page 4: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Part 1: Language

Part 2: Paradigm

Part 3: Style

Page 5: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Part 1: Language

Page 6: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

What languagesare the norm today?

Page 7: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Global developer population report 2019

Page 8: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Total functional

programming languages:

0

Page 9: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

1. Killer App

2. Platform Exclusivity

3. Quick Upgrade

How did they get popular?

Page 10: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

1. Killer App

Page 11: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Software:$100

Hardware:$10000

Page 12: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

“VisiCalc is the first program

available on a microcomputer

that has been responsible for

sales of entire systems.”

-BYTE magazine, 1980

Page 13: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

the killer app for

Page 14: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 15: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

the killer app for

making HTML dynamic

Page 16: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 17: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

the killer app for

systems programming

Page 18: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 19: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Elm

Clojure

ReasonML

Potential FP Killer Appselm-ui

Datomic

revery

Page 20: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

2. Platform Exclusivity

Page 21: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 22: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 23: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

iPhone Sales

Page 24: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 25: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 26: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 27: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

“Write once, run anywhere.”

Page 28: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

3. Quick Upgrade

Page 29: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Benefits

Familiarity

Learning Curve

Ecosystem Access

Code Migration Effort

“It’s just JavaScript”Considerations

Page 30: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

“It’s just JavaScript”Benefits

Familiarity

Learning Curve

Ecosystem Access

Code Migration Effort

strict superset of JS

Considerations

Page 31: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Benefits

Familiarity

Learning Curve

Ecosystem Access

Code Migration Effort

near-superset of C

Considerations

Page 32: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Benefits

Familiarity

Learning Curve

Ecosystem Access

Code Migration Effort

“Kotlin is 100% interoperable with [Java] and major emphasis has been placed on making sure that your existing codebase can interact properly with Kotlin.”

Considerations

Page 33: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

1. Killer App

2. Platform Exclusivity

3. Quick Upgrade

How did they get popular?C, Ruby, PHP

JS, Objective-C, Swift, C#

C++, Kotlin, TypeScript

Page 34: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

1. Killer App

2. Platform Exclusivity

3. Quick Upgrade

4. Epic Marketing

How did they get popular?C, Ruby, PHP

JS, Objective-C, Swift, C#

C++, Kotlin, TypeScript

Java

Page 35: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

$500M Java marketing campaign in 2003

Page 36: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 37: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

1. Killer App

2. Platform Exclusivity

3. Quick Upgrade

4. Epic Marketing

5. Slow & Steady

1. Killer App

2. Platform Exclusivity

3. Quick Upgrade

4. Epic Marketing

How did they get popular?C, Ruby, PHP

JS, Objective-C, Swift, C#

C++, Kotlin, TypeScript

Java

Python

Page 38: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 39: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Syntax

Job Market

Community

Other Popularity Factors

Page 40: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Why are the most popular languages OO(except C)?

Page 41: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Part 2: Paradigm

Page 42: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Programming paradigms are a way toclassify programming languages based on their features.Languages can be classified into multiple paradigms.

Page 43: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Are OO languages the normbecause of uniquely OO features?

Page 44: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

1. Encapsulation?

2. Inheritance?

3. Objects?

4. Methods?

What are uniquely OO features?

Page 45: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Inheritance

Interface Inheritance (aka subtyping)

Implementation Inheritance (aka inheritance)

Page 46: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

“Composition over inheritance”

Page 47: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

“Supports an object-oriented style”

No inheritance

“Objects and methods” are

syntax sugar for structs and procedures

encapsulation?

circle.grow(3)

grow(circle, 3)

Page 48: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Modular Programming

Modularity lets you define a public interfaceto hide private implementation details

Page 49: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Languages with modules

*coming in C++20

Page 50: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Modular Programming

Modularity lets you define a public interfaceto hide private implementation details

Page 51: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Encapsulation

Encapsulation lets you define a public interfaceto hide private implementation detailsabout an object’s state

Page 52: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

ObjectsClasses

InheritanceGarbage Collection

John McCarthy,Creator of Lisp

Page 53: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

ObjectsClasses

InheritanceGarbage Collection

“Object-Oriented” -Alan Kayeverything is an object

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I’m not aware of them.

bit.ly/2kqxVWO

Page 54: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

“I wasn't happy with C as a productivity foundation, and I was lobbying around for anything that could help. That was about the time the Byte Magazine issue came out.”

ObjectsClasses

InheritanceGarbage CollectionBrad Cox

“I wasn't happy with C as a productivity foundation, and I was lobbying around for anything that could help. That was about the time the Byte Magazine issue came out.” “There were a whole bunch of things I thought vaguely might help. Encapsulation for sure...C is so bad at it. Everything is public; it just turns into soup.The pain of that is what I was trying to escape.”

youtu.be/1xrL2d5omuA

“I wasn't happy with C as a productivity foundation, and I was lobbying around for anything that could help. That was about the time the Byte Magazine issue came out.” “There were a whole bunch of things I thought vaguely might help. Encapsulation for sure...C is so bad at it.

“I wasn't happy with C as a productivity foundation, and I was lobbying around for anything that could help. That was about the time the Byte Magazine issue came out.” “There were a whole bunch of things I thought vaguely might help. Encapsulation for sure...C is so bad at it. Everything is public; it just turns into soup.

Page 55: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 56: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

ObjectsClasses

InheritanceGarbage Collection

WithClasses

Bjarne Stroustrup

Page 57: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

WithClasses

Bjarne Stroustrup

youtu.be/69edOm889V4

Drop-in C Replacement (!)

Page 58: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

C with OOP (“C with Classes”) wasn’t sufficient for popularity

Sun wanted familiarity for C++ programmers

Microsoft wanted a proprietary Java alternative

Brad Cox wanted modularity

Apple wanted to improve on ObjC

Page 59: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 60: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

“I wanted a scripting language that

was more powerful than Perl, and

more object-oriented than Python.”

—Yukihiro “Matz” Matsumoto,

creator of Ruby

Page 61: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 62: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Are OO languages the normbecause of uniquely OO features?

They’re OO because modularity is a good idea,and they originally got it from OO by chance.

No.

Page 63: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Part 3: Style

Page 64: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Functional Programming Style

“Avoid mutation and side effects.”

No language features required

Languages differ in their support for this style

Page 65: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Why isn’t FP style the norm?

Page 66: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Kotlin has both object-oriented and functional constructs.

You can use it in both OO and FP styles, or mix elements of the two.

FAQIs Kotlin an object-oriented language or a functional one?

Page 67: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Functional programming patterns, e.g., map and filter

Some additional features of Swift include:

swift.org

Page 68: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 69: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 70: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 71: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional
Page 72: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

OO style FP stylehybrid

Page 73: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

“Wouldn’t it be nice if my language had strong support for the style that’s become the norm?”

??????????

Page 74: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Why isn’t Functional Programming the Norm?

@rtfeldman

Page 75: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Part 1: Language

Part 2: Paradigm

Part 3: Style

Page 76: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

1. No sufficiently large “killer apps”

2. No exclusivity on large platforms

3. Can’t be a quick upgrade if substantially different

4. No epic marketing budgets

5. Slow & steady growth takes decades

Why aren’t FP languages the norm?

Page 77: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

1. Information hiding (encapsulation) is nota uniquely OO feature. Modules can do it too.

2. Inheritance is uniquely OO, but OO best practice encourages using composition instead.

3. Without inheritance, objects and methods are notsignificantly different from structs and procedures.

Are OO languages the normbecause of uniquely OO features?

Page 78: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

Why isn’t FP style the norm?

Page 79: Why isn’t Functional Programming the Norm? · Clojure ReasonML Potential FP Killer Apps elm-ui Datomic revery. 2. Platform Exclusivity. iPhone Sales “Write once, ... Functional

@rtfeldman