SlideShare una empresa de Scribd logo
1 de 107
Descargar para leer sin conexión
NewCrafts 2019
Four Languages From
FortyYears Ago
@ScottWlaschin
fsharpforfunandprofit.com
a.k.a What can we learn
from the 1970's?
I'm old …
I'm so old that I was
actually alive in the 1970's
Me
The 1970's
How much do you know
about the 1970's?
Do you know these 1970's classics?
Do you know these 1970's classics?
Do you know these 1970's classics?
Prolog
ML family
What does your toolkit
look like?
Does your DIY toolkit look like this?
For hammering nails:
For screwing things in:
For cutting wood:
For tightening bolts:
I hope not! That would be silly!
Does your programming toolkit look like this?
For domain modeling:
For complex business rules:
For querying data:
For live coding:
Hmmmm...
Don't use hammers only…
…expand your toolkit!
"A language that doesn't affect the way
you think about programming, is not
worth knowing" – Alan Perlis
Galaxy Brain
seal of approval
How to expand your toolkit?
The most popular programming languages
• Java
• JavaScript
• C++
• C
• C#
• Python
• PHP
• Ruby
• Visual Basic
• Go
Australian English
British English
"I speak three languages"
It's a big world out there
Not every language looks like C or C# or Java or JavaScript
What programming paradigms
do you need to know?
The most important programming paradigms
• Imperative-procedural
– ALGOL, 1960
• Object-oriented
– Simula 1967
– Smalltalk 1976
• Functional
– ML 1972
• Symbolic
– Lisp 1959
– Maclisp/Scheme 1970's
• Logic
– Prolog 1973
• Concatenative
– Forth 1970
...and all paradigms had
stabilized by mid-1980's
Concepts originated in
the 1970's...
Are you caught up
with the state of the art
from 35 years ago?
So…
let's go back to the 1970's…
SQL (1974)
SQL background
• Part of IBM's System R, the first practical
relational database.
• Before SQL: the dark ages of proprietary and
custom database query APIs.
Learning from SQL #1:
A consistent model
Everything is a set of relations
TABLE Person
| Name | Age |
|---------|-----|
| Liz | 92 |
| Charles | 69 |
| Wills | 35 |
| Harry | 33 |
TABLE ParentChild
| Parent | Child |
|---------|---------|
| Diana | Wills |
| Diana | Harry |
| Charles | Wills |
| Charles | Harry |
| Liz | Charles |
| Name | Age |
|---------|-----|
| Liz | 92 |
| Charles | 69 |
| Wills | 35 |
| Harry | 33 |
SELECT Name FROM Person
The result is another set
of relations
| Name | Age |
|---------|-----|
| Liz | 92 |
| Charles | 69 |
| Wills | 35 |
| Harry | 33 |
SELECT * FROM Person WHERE Age > 50
The result is another set
of relations
SELECT Parent,Age
FROM Person
OUTER JOIN ParentChild
WHERE Parent = Person
"Set operations, huh?
I bet there's a way to do
cartesian products then."
Consistency => Predictability
Here you go:
Learning from SQL #2:
Composability
It's an expression-oriented language
SELECT Name
FROM Person
WHERE Age > 50
You can take a query like this:
And embed it as a subquery
SELECT Child
FROM ParentChild
WHERE Parent IN
(SELECT Name
FROM Person
WHERE Age > 50)
And embed *that* as a subquery
SELECT Child as Grandchild
FROM ParentChild
WHERE Parent IN
( SELECT Child
FROM ParentChild
WHERE Parent IN
(SELECT Name
FROM Person
WHERE Age > 50))
Expressions are great, part 1:
Expressions are composable

There's another reason to prefer
expressions over statements…
They eliminate many types of error
void ifThenElseStatement(bool aBool)
{
int result;
if (aBool)
{
result = 42;
}
printfn("result=%i", result);
}
How many things could cause problems in this C-like code?
void ifThenElseStatement(bool aBool)
{
int result;
if (aBool)
{
result = 42;
}
printfn("result=%i", result);
}
How many things could cause problems in this C-like code?
void ifThenElseStatement(bool aBool)
{
int result;
if (aBool)
{
result = 42;
}
printfn("result=%i", result);
}
How many things could cause problems in this C-like code?
void ifThenElseStatement(bool aBool)
{
int result;
if (aBool)
{
result = 42;
}
printfn("result=%i", result);
}
How many things could cause problems in this C-like code?
void ifThenElseStatement(bool aBool)
{
int result;
if (aBool)
{
result = 42;
}
printfn("result=%i", result);
}
How many things could cause problems in this C-like code?
public void IfThenElseExpression(bool aBool)
{
int result = aBool ? 42 : 0;
Console.WriteLine("result={0}", result);
}
The same C-like code written in an expression-oriented way
public void IfThenElseExpression(bool aBool)
{
int result = aBool ? 42 : 0;
Console.WriteLine("result={0}", result);
}
The same C-like code written in an expression-oriented way
public void IfThenElseExpression(bool aBool)
{
int result = aBool ? 42 : 0;
Console.WriteLine("result={0}", result);
}
The same C-like code written in an expression-oriented way
public void IfThenElseExpression(bool aBool)
{
int result = aBool ? 42 : 0;
Console.WriteLine("result={0}", result);
}
The same C-like code written in an expression-oriented way
public void IfThenElseExpression(bool aBool)
{
int result = aBool ? 42 : 0;
Console.WriteLine("result={0}", result);
}
The same C-like code written in an expression-oriented way
int StandaloneSubexpression(bool aBool)
{
return aBool ? 42 : 0;
}
Expressions are great, part 2:
Expressions reduce bugs
and make refactoring easier

Learning from SQL #3:
It's declarative
"What" not "How"
FILE *stream;
char *line = NULL;
size_t len = 0;
ssize_t nread;
stream = fopen(argv[1], "r");
while ((nread = getline(&line, &len, stream)) != -1) {
/* check what the age is */
if age > 50
fwrite(line, nread, 1, stdout);
}
free(line);
fclose(stream);
Example of "How" programming
SELECT * FROM Person WHERE Age > 50
Example of "What" programming
Learning from SQL #4:
Separation of concerns
It's a QUERY language!
SQL: Separation of concerns
• It's a QUERY language, doh!
– A Data Query Language
• Insert/Update/Delete is a different language
– A Data Manipulation Language
• Defining tables etc. is a different language again
– A Data Definition Language
• "SQL" now means all of these together.
What can we learn from SQL?
• Consistent model
– And predictable
• Composable
– Because expression-based
• Declarative interface
– "What", not "how"
• Separation of concerns
– Reinvented as Command-Query Separation
• Interactivity is important
– You can play and experiment
Prolog (1972)
Prolog background
• First mainstream logic programming language
– Designed in Marseille, France.
– From "programmation en logique"
• European answer to LISP for AI.
– But now just as esoteric 
Learning from Prolog #1:
A consistent model
Everything is a fact or a rule
Facts
age(liz,92).
age(charles,69).
age(wills,35).
age(harry,33).
parent(charles,wills).
parent(charles,harry).
parent(liz,charles).
Rules
grandparent(GP,C) :-
parent(GP,P),
parent(P,C).
isOlder(P1,P2) :-
age(P1,A1),
age(P2,A2),
A1 > A2.
Learning from Prolog #2:
It's declarative
"What" not "How"
age(liz,92). % is it a fact?
true.
age(P,92). % P is unbound, so tell me
P=liz.
age(liz,A). % A is unbound
A=92.
grandparent(liz,harry).
true.
isOlder(wills,liz).
false.
grandparent(liz,P). % P is unbound
P=harry.
P=wills.
isOlder(P,charles). % P is unbound
P=liz.
Rules and facts look the same
% what is [1] followed by [2,3] ?
append([1], [2,3], X).
X = [1,2,3] % only one answer
% what do you prepend to [2,3] to make [1,2,3]?
append(X, [2,3], [1,2,3]).
X = [1] % only one answer
% how many ways can you make [1,2,3]?
append(X, Y, [1,2,3]).
X = [] Y =[1,2,3] % multiple answers
X = [1] Y =[2,3]
X = [1,2] Y =[3]
X = [1,2,3] Y =[]
Bi-directional unification is awesome
Prolog demo
What can we learn from Prolog?
• Consistent model (again)
• Declarative (again)
– "What" not "how" in the Sudoku example
• Unification is very cool
– Bi-directional queries
– Ask both "is true?" and "what matches?"
• Interactivity is important (again)
ML (1973)
Parent of SML, OCaml and F#
ML background
• "ML" for "Meta Language"
– Designed as part of a theorem-proving system
– Not to be confused with Machine Learning.
• An impure functional language
– Parent of Standard ML, OCaml, F#
Learning from ML #1:
A consistent model
Functions are "normal" things
just like ints, strings, bools, etc.
Don't worry.
I'm not going to talk about
functional programming.
Learning from ML #2:
Type inference
let doSomething f x =
let y = f (x + 1)
"hello" + y
NOTE: I can't show the original ML from the 1970's,
so I'm using F# instead.
let doSomething f x =
let y = f (x + 1)
"hello" + y
let doSomething f x =
let y = f (x + 1)
"hello" + y
Inferred type of doSomething :
f:(int -> string) -> x:int -> string
// C# code
public IEnumerable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(
IEnumerable<TSource> source,
Func<TSource, TKey> keySelector
)
{
...
}
// F# code
let GroupBy source keySelector =
...
Benefits of type inference:
* Less typing
* Less noise, more logic
Here's a more complex example
Learning from ML #3:
Sensible defaults
Sensible defaults
• Immutable by default
– Mutable is a special case
• Non-nullable types by default
– Nullable is a special case
• Structural equality by default
– Reference equality is special case
• Everything must be initialized
Learning from ML #4:
Algebraic type system
NB: Technically not part of original ML but
now a standard part of "ML family"
New types are built from smaller types by:
Composing with “AND”
Composing with “OR”
Example: pairs, tuples, records
FruitSalad = One each of and and
Compose with “AND”
type FruitSalad = {
Apple: AppleVariety
Banana: BananaVariety
Cherry: CherryVariety
}
Snack = or or
Compose with “OR”
type Snack =
| Apple of AppleVariety
| Banana of BananaVariety
| Cherry of CherryVariety
A real world example
of composing types
Some requirements:
We accept three forms of payment:
Cash, Check, or Card.
For Cash we don't need any extra information
For Checks we need a check number
For Cards we need a card type and card number
type CheckNumber = int
type CardNumber = string
With an algebraic type system you would probably
implement by composing types, like this:
type CheckNumber = ...
type CardNumber = …
type CardType = Visa | Mastercard
type CreditCardInfo = {
CardType : CardType
CardNumber : CardNumber
}
type CheckNumber = ...
type CardNumber = ...
type CardType = ...
type CreditCardInfo = ...
type PaymentMethod =
| Cash
| Check of CheckNumber
| Card of CreditCardInfo
type CheckNumber = ...
type CardNumber = ...
type CardType = ...
type CreditCardInfo = ...
type PaymentMethod =
| Cash
| Check of CheckNumber
| Card of CreditCardInfo
type PaymentAmount = decimal
type Currency = EUR | USD
type CheckNumber = ...
type CardNumber = ...
type CardType = ...
type CreditCardInfo = ...
type PaymentMethod =
| Cash
| Check of CheckNumber
| Card of CreditCardInfo
type PaymentAmount = decimal
type Currency = EUR | USD
type Payment = {
Amount : PaymentAmount
Currency : Currency
Method : PaymentMethod }
type CheckNumber = ...
type CardNumber = ...
type CardType = ...
type CreditCardInfo = ...
type PaymentMethod =
| Cash
| Check of CheckNumber
| Card of CreditCardInfo
type PaymentAmount = decimal
type Currency = EUR | USD
type Payment = {
Amount : PaymentAmount
Currency : Currency
Method : PaymentMethod }
Types can become
executable documentation
type Deal = Deck -> (Deck * Card)
type PickupCard = (Hand * Card) -> Hand
type Suit = Club | Diamond | Spade | Heart
type Rank = Two | Three | Four | Five | Six | Seven | Eight
| Nine | Ten | Jack | Queen | King | Ace
type Card = { Suit:Suit; Rank:Rank }
type Hand = Card list
type Deck = Card list
type Player = {Name:string; Hand:Hand}
type Game = { Deck:Deck; Players:Player list }
The domain on one screen!
type PaymentMethod =
| Cash
| Check of CheckNumber
| Card of CreditCardInfo
A big topic and not enough time  
More on DDD and designing with types at
fsharpforfunandprofit.com/ddd
I could do an ML demo here
But I won't!
What can we learn from ML?
• Consistent model (again)
• Expression-based (again)
– Everything is composable
– Also prevents bugs
• Type inference is awesome
• Sensible defaults make accidents harder
– E.g. immutable by default
• Algebraic types are awesome
Smalltalk (1976)
I
Is a simulation of a teletype really the best interface
for interacting with an operating system?
-- @gambler on HN, Jan 2019
Smalltalk background
• Developed at Xerox PARC
– Along with the first PC, the first GUI, the first
laser printer, ethernet, and more.
• Smalltalk introduced
– Message-based OO
– Model-View-Controller
– A windowing IDE
– Also had aVM, generational GC, etc.
Smalltalk-80 User Interface
Learning from Smalltalk #1:
A consistent model:
everything is an object
everything is an object
everything is an object
everything is an object
Learning from Smalltalk #2:
Minimal syntax
Learning from Smalltalk #2:
Minimal syntax
Put the power in the language instead.
Learning from Smalltalk #2:
Minimal syntax
Put the power in the language instead.
Learning from Smalltalk #3:
Late binding
If you're going to be a dynamic language,
be a really dynamic language.
Learning from Smalltalk #4:
Who needs text files?
If everything is accessible
you have a lot of power
Smalltalk demo
What can we learn from Smalltalk?
• A consistent model, again
• Minimize syntax and make the language
powerful
• Be awesome and make people fall in love with
you!
Conclusion
What can we learn from the 1970's?
• Many great ideas were developed 40 years ago
– They should be more widely known
• There are many different approaches to solving
problems.
– A bigger toolbox is a good thing to have
– Use the right tool for the job
And one more thing…
C-style syntax is not the only possible syntax!
– No curly braces
– Sentences can end properly, with a period!
– No dot syntax (not even in OO Smalltalk)
"A language that doesn't affect the way you
think about programming, is not worth
knowing" – Alan Perlis
So go forth and expand your Galaxy Brain!
Slides and video here
fsharpforfunandprofit.com/fourfromforty
Thank you!
"Domain modelling Made Functional" book
fsharpforfunandprofit.com/books
@ScottWlaschin Me on twitter

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Python slide
Python slidePython slide
Python slide
 
Domain Driven Design with the F# type System -- NDC London 2013
Domain Driven Design with the F# type System -- NDC London 2013Domain Driven Design with the F# type System -- NDC London 2013
Domain Driven Design with the F# type System -- NDC London 2013
 
The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)The Functional Programmer's Toolkit (NDC London 2019)
The Functional Programmer's Toolkit (NDC London 2019)
 
The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)The Functional Programming Toolkit (NDC Oslo 2019)
The Functional Programming Toolkit (NDC Oslo 2019)
 
Domain Modeling with FP (DDD Europe 2020)
Domain Modeling with FP (DDD Europe 2020)Domain Modeling with FP (DDD Europe 2020)
Domain Modeling with FP (DDD Europe 2020)
 
Declare Your Language: Type Checking
Declare Your Language: Type CheckingDeclare Your Language: Type Checking
Declare Your Language: Type Checking
 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term Rewriting
 
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1
Scala 3 by Example - Algebraic Data Types for Domain Driven Design - Part 1
 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) Services
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
Types and perl language
Types and perl languageTypes and perl language
Types and perl language
 
Python language data types
Python language data typesPython language data types
Python language data types
 
DISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaDISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in Java
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
 
Python revision tour i
Python revision tour iPython revision tour i
Python revision tour i
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 

Similar a Four Languages From Forty Years Ago (NewCrafts 2019)

Peter Norvig - NYC Machine Learning 2013
Peter Norvig - NYC Machine Learning 2013Peter Norvig - NYC Machine Learning 2013
Peter Norvig - NYC Machine Learning 2013
Michael Scovetta
 
Stop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesStop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principles
Edorian
 
Introduction to the Algorithm Game
Introduction to the Algorithm GameIntroduction to the Algorithm Game
Introduction to the Algorithm Game
Ivan Orozco
 

Similar a Four Languages From Forty Years Ago (NewCrafts 2019) (20)

Peter Norvig - NYC Machine Learning 2013
Peter Norvig - NYC Machine Learning 2013Peter Norvig - NYC Machine Learning 2013
Peter Norvig - NYC Machine Learning 2013
 
Learn Python 3 for absolute beginners
Learn Python 3 for absolute beginnersLearn Python 3 for absolute beginners
Learn Python 3 for absolute beginners
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Mastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loopsMastering Python lesson3b_for_loops
Mastering Python lesson3b_for_loops
 
Intro
IntroIntro
Intro
 
Seven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many ProgrammersSeven Ineffective Coding Habits of Many Programmers
Seven Ineffective Coding Habits of Many Programmers
 
2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge
 
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
How to avoid Go gotchas - Ivan Daniluk - Codemotion Milan 2016
 
Stop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principlesStop wasting-time-by-applying-clean-code-principles
Stop wasting-time-by-applying-clean-code-principles
 
Python For Machine Learning
Python For Machine LearningPython For Machine Learning
Python For Machine Learning
 
Introduction to the Algorithm Game
Introduction to the Algorithm GameIntroduction to the Algorithm Game
Introduction to the Algorithm Game
 
CoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming course
 
OpenRepGrid and Friends
OpenRepGrid and FriendsOpenRepGrid and Friends
OpenRepGrid and Friends
 
F# Eye for the C# Guy
F# Eye for the C# GuyF# Eye for the C# Guy
F# Eye for the C# Guy
 
Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog Language
 
Introductionof c
Introductionof cIntroductionof c
Introductionof c
 
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
 
ForLoops.pptx
ForLoops.pptxForLoops.pptx
ForLoops.pptx
 
Class 4: For and while
Class 4: For and whileClass 4: For and while
Class 4: For and while
 

Más de Scott Wlaschin

Más de Scott Wlaschin (17)

Domain Modeling Made Functional (DevTernity 2022)
Domain Modeling Made Functional (DevTernity 2022)Domain Modeling Made Functional (DevTernity 2022)
Domain Modeling Made Functional (DevTernity 2022)
 
Pipeline oriented programming
Pipeline oriented programmingPipeline oriented programming
Pipeline oriented programming
 
The Power of Composition (NDC Oslo 2020)
The Power of Composition (NDC Oslo 2020)The Power of Composition (NDC Oslo 2020)
The Power of Composition (NDC Oslo 2020)
 
The lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of testsThe lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of tests
 
Functional Design Patterns (DevTernity 2018)
Functional Design Patterns (DevTernity 2018)Functional Design Patterns (DevTernity 2018)
Functional Design Patterns (DevTernity 2018)
 
Designing with capabilities (DDD-EU 2017)
Designing with capabilities (DDD-EU 2017)Designing with capabilities (DDD-EU 2017)
Designing with capabilities (DDD-EU 2017)
 
Thirteen ways of looking at a turtle
Thirteen ways of looking at a turtleThirteen ways of looking at a turtle
Thirteen ways of looking at a turtle
 
Designing with Capabilities
Designing with CapabilitiesDesigning with Capabilities
Designing with Capabilities
 
Dr Frankenfunctor and the Monadster
Dr Frankenfunctor and the MonadsterDr Frankenfunctor and the Monadster
Dr Frankenfunctor and the Monadster
 
Enterprise Tic-Tac-Toe
Enterprise Tic-Tac-ToeEnterprise Tic-Tac-Toe
Enterprise Tic-Tac-Toe
 
An introduction to property based testing
An introduction to property based testingAn introduction to property based testing
An introduction to property based testing
 
Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)
 
Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)Functional Programming Patterns (BuildStuff '14)
Functional Programming Patterns (BuildStuff '14)
 
Swift vs. Language X
Swift vs. Language XSwift vs. Language X
Swift vs. Language X
 
Doge-driven design
Doge-driven designDoge-driven design
Doge-driven design
 
Railway Oriented Programming
Railway Oriented ProgrammingRailway Oriented Programming
Railway Oriented Programming
 
The Theory of Chains
The Theory of ChainsThe Theory of Chains
The Theory of Chains
 

Último

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 

Four Languages From Forty Years Ago (NewCrafts 2019)

  • 1. NewCrafts 2019 Four Languages From FortyYears Ago @ScottWlaschin fsharpforfunandprofit.com a.k.a What can we learn from the 1970's?
  • 2. I'm old … I'm so old that I was actually alive in the 1970's
  • 4. How much do you know about the 1970's?
  • 5. Do you know these 1970's classics?
  • 6. Do you know these 1970's classics?
  • 7. Do you know these 1970's classics? Prolog ML family
  • 8. What does your toolkit look like?
  • 9. Does your DIY toolkit look like this? For hammering nails: For screwing things in: For cutting wood: For tightening bolts: I hope not! That would be silly!
  • 10. Does your programming toolkit look like this? For domain modeling: For complex business rules: For querying data: For live coding: Hmmmm...
  • 11. Don't use hammers only… …expand your toolkit!
  • 12. "A language that doesn't affect the way you think about programming, is not worth knowing" – Alan Perlis Galaxy Brain seal of approval
  • 13. How to expand your toolkit?
  • 14. The most popular programming languages • Java • JavaScript • C++ • C • C# • Python • PHP • Ruby • Visual Basic • Go
  • 15. Australian English British English "I speak three languages"
  • 16. It's a big world out there Not every language looks like C or C# or Java or JavaScript
  • 17. What programming paradigms do you need to know?
  • 18. The most important programming paradigms • Imperative-procedural – ALGOL, 1960 • Object-oriented – Simula 1967 – Smalltalk 1976 • Functional – ML 1972 • Symbolic – Lisp 1959 – Maclisp/Scheme 1970's • Logic – Prolog 1973 • Concatenative – Forth 1970 ...and all paradigms had stabilized by mid-1980's Concepts originated in the 1970's...
  • 19. Are you caught up with the state of the art from 35 years ago?
  • 20. So… let's go back to the 1970's…
  • 22. SQL background • Part of IBM's System R, the first practical relational database. • Before SQL: the dark ages of proprietary and custom database query APIs.
  • 23. Learning from SQL #1: A consistent model Everything is a set of relations
  • 24. TABLE Person | Name | Age | |---------|-----| | Liz | 92 | | Charles | 69 | | Wills | 35 | | Harry | 33 | TABLE ParentChild | Parent | Child | |---------|---------| | Diana | Wills | | Diana | Harry | | Charles | Wills | | Charles | Harry | | Liz | Charles |
  • 25. | Name | Age | |---------|-----| | Liz | 92 | | Charles | 69 | | Wills | 35 | | Harry | 33 | SELECT Name FROM Person The result is another set of relations
  • 26. | Name | Age | |---------|-----| | Liz | 92 | | Charles | 69 | | Wills | 35 | | Harry | 33 | SELECT * FROM Person WHERE Age > 50 The result is another set of relations
  • 27. SELECT Parent,Age FROM Person OUTER JOIN ParentChild WHERE Parent = Person "Set operations, huh? I bet there's a way to do cartesian products then." Consistency => Predictability Here you go:
  • 28. Learning from SQL #2: Composability It's an expression-oriented language
  • 29. SELECT Name FROM Person WHERE Age > 50 You can take a query like this:
  • 30. And embed it as a subquery SELECT Child FROM ParentChild WHERE Parent IN (SELECT Name FROM Person WHERE Age > 50)
  • 31. And embed *that* as a subquery SELECT Child as Grandchild FROM ParentChild WHERE Parent IN ( SELECT Child FROM ParentChild WHERE Parent IN (SELECT Name FROM Person WHERE Age > 50))
  • 32. Expressions are great, part 1: Expressions are composable 
  • 33. There's another reason to prefer expressions over statements… They eliminate many types of error
  • 34. void ifThenElseStatement(bool aBool) { int result; if (aBool) { result = 42; } printfn("result=%i", result); } How many things could cause problems in this C-like code?
  • 35. void ifThenElseStatement(bool aBool) { int result; if (aBool) { result = 42; } printfn("result=%i", result); } How many things could cause problems in this C-like code?
  • 36. void ifThenElseStatement(bool aBool) { int result; if (aBool) { result = 42; } printfn("result=%i", result); } How many things could cause problems in this C-like code?
  • 37. void ifThenElseStatement(bool aBool) { int result; if (aBool) { result = 42; } printfn("result=%i", result); } How many things could cause problems in this C-like code?
  • 38. void ifThenElseStatement(bool aBool) { int result; if (aBool) { result = 42; } printfn("result=%i", result); } How many things could cause problems in this C-like code?
  • 39. public void IfThenElseExpression(bool aBool) { int result = aBool ? 42 : 0; Console.WriteLine("result={0}", result); } The same C-like code written in an expression-oriented way
  • 40. public void IfThenElseExpression(bool aBool) { int result = aBool ? 42 : 0; Console.WriteLine("result={0}", result); } The same C-like code written in an expression-oriented way
  • 41. public void IfThenElseExpression(bool aBool) { int result = aBool ? 42 : 0; Console.WriteLine("result={0}", result); } The same C-like code written in an expression-oriented way
  • 42. public void IfThenElseExpression(bool aBool) { int result = aBool ? 42 : 0; Console.WriteLine("result={0}", result); } The same C-like code written in an expression-oriented way
  • 43. public void IfThenElseExpression(bool aBool) { int result = aBool ? 42 : 0; Console.WriteLine("result={0}", result); } The same C-like code written in an expression-oriented way int StandaloneSubexpression(bool aBool) { return aBool ? 42 : 0; }
  • 44. Expressions are great, part 2: Expressions reduce bugs and make refactoring easier 
  • 45. Learning from SQL #3: It's declarative "What" not "How"
  • 46. FILE *stream; char *line = NULL; size_t len = 0; ssize_t nread; stream = fopen(argv[1], "r"); while ((nread = getline(&line, &len, stream)) != -1) { /* check what the age is */ if age > 50 fwrite(line, nread, 1, stdout); } free(line); fclose(stream); Example of "How" programming
  • 47. SELECT * FROM Person WHERE Age > 50 Example of "What" programming
  • 48. Learning from SQL #4: Separation of concerns It's a QUERY language!
  • 49. SQL: Separation of concerns • It's a QUERY language, doh! – A Data Query Language • Insert/Update/Delete is a different language – A Data Manipulation Language • Defining tables etc. is a different language again – A Data Definition Language • "SQL" now means all of these together.
  • 50. What can we learn from SQL? • Consistent model – And predictable • Composable – Because expression-based • Declarative interface – "What", not "how" • Separation of concerns – Reinvented as Command-Query Separation • Interactivity is important – You can play and experiment
  • 52. Prolog background • First mainstream logic programming language – Designed in Marseille, France. – From "programmation en logique" • European answer to LISP for AI. – But now just as esoteric 
  • 53. Learning from Prolog #1: A consistent model Everything is a fact or a rule
  • 55. Learning from Prolog #2: It's declarative "What" not "How"
  • 56. age(liz,92). % is it a fact? true. age(P,92). % P is unbound, so tell me P=liz. age(liz,A). % A is unbound A=92.
  • 57. grandparent(liz,harry). true. isOlder(wills,liz). false. grandparent(liz,P). % P is unbound P=harry. P=wills. isOlder(P,charles). % P is unbound P=liz. Rules and facts look the same
  • 58. % what is [1] followed by [2,3] ? append([1], [2,3], X). X = [1,2,3] % only one answer % what do you prepend to [2,3] to make [1,2,3]? append(X, [2,3], [1,2,3]). X = [1] % only one answer % how many ways can you make [1,2,3]? append(X, Y, [1,2,3]). X = [] Y =[1,2,3] % multiple answers X = [1] Y =[2,3] X = [1,2] Y =[3] X = [1,2,3] Y =[] Bi-directional unification is awesome
  • 60. What can we learn from Prolog? • Consistent model (again) • Declarative (again) – "What" not "how" in the Sudoku example • Unification is very cool – Bi-directional queries – Ask both "is true?" and "what matches?" • Interactivity is important (again)
  • 61. ML (1973) Parent of SML, OCaml and F#
  • 62. ML background • "ML" for "Meta Language" – Designed as part of a theorem-proving system – Not to be confused with Machine Learning. • An impure functional language – Parent of Standard ML, OCaml, F#
  • 63. Learning from ML #1: A consistent model Functions are "normal" things just like ints, strings, bools, etc.
  • 64. Don't worry. I'm not going to talk about functional programming.
  • 65. Learning from ML #2: Type inference
  • 66. let doSomething f x = let y = f (x + 1) "hello" + y NOTE: I can't show the original ML from the 1970's, so I'm using F# instead.
  • 67. let doSomething f x = let y = f (x + 1) "hello" + y
  • 68. let doSomething f x = let y = f (x + 1) "hello" + y Inferred type of doSomething : f:(int -> string) -> x:int -> string
  • 69. // C# code public IEnumerable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>( IEnumerable<TSource> source, Func<TSource, TKey> keySelector ) { ... } // F# code let GroupBy source keySelector = ... Benefits of type inference: * Less typing * Less noise, more logic Here's a more complex example
  • 70. Learning from ML #3: Sensible defaults
  • 71. Sensible defaults • Immutable by default – Mutable is a special case • Non-nullable types by default – Nullable is a special case • Structural equality by default – Reference equality is special case • Everything must be initialized
  • 72. Learning from ML #4: Algebraic type system NB: Technically not part of original ML but now a standard part of "ML family"
  • 73. New types are built from smaller types by: Composing with “AND” Composing with “OR”
  • 74. Example: pairs, tuples, records FruitSalad = One each of and and Compose with “AND” type FruitSalad = { Apple: AppleVariety Banana: BananaVariety Cherry: CherryVariety }
  • 75. Snack = or or Compose with “OR” type Snack = | Apple of AppleVariety | Banana of BananaVariety | Cherry of CherryVariety
  • 76. A real world example of composing types
  • 77. Some requirements: We accept three forms of payment: Cash, Check, or Card. For Cash we don't need any extra information For Checks we need a check number For Cards we need a card type and card number
  • 78. type CheckNumber = int type CardNumber = string With an algebraic type system you would probably implement by composing types, like this:
  • 79. type CheckNumber = ... type CardNumber = … type CardType = Visa | Mastercard type CreditCardInfo = { CardType : CardType CardNumber : CardNumber }
  • 80. type CheckNumber = ... type CardNumber = ... type CardType = ... type CreditCardInfo = ... type PaymentMethod = | Cash | Check of CheckNumber | Card of CreditCardInfo
  • 81. type CheckNumber = ... type CardNumber = ... type CardType = ... type CreditCardInfo = ... type PaymentMethod = | Cash | Check of CheckNumber | Card of CreditCardInfo type PaymentAmount = decimal type Currency = EUR | USD
  • 82. type CheckNumber = ... type CardNumber = ... type CardType = ... type CreditCardInfo = ... type PaymentMethod = | Cash | Check of CheckNumber | Card of CreditCardInfo type PaymentAmount = decimal type Currency = EUR | USD type Payment = { Amount : PaymentAmount Currency : Currency Method : PaymentMethod }
  • 83. type CheckNumber = ... type CardNumber = ... type CardType = ... type CreditCardInfo = ... type PaymentMethod = | Cash | Check of CheckNumber | Card of CreditCardInfo type PaymentAmount = decimal type Currency = EUR | USD type Payment = { Amount : PaymentAmount Currency : Currency Method : PaymentMethod }
  • 85. type Deal = Deck -> (Deck * Card) type PickupCard = (Hand * Card) -> Hand type Suit = Club | Diamond | Spade | Heart type Rank = Two | Three | Four | Five | Six | Seven | Eight | Nine | Ten | Jack | Queen | King | Ace type Card = { Suit:Suit; Rank:Rank } type Hand = Card list type Deck = Card list type Player = {Name:string; Hand:Hand} type Game = { Deck:Deck; Players:Player list } The domain on one screen!
  • 86. type PaymentMethod = | Cash | Check of CheckNumber | Card of CreditCardInfo
  • 87. A big topic and not enough time   More on DDD and designing with types at fsharpforfunandprofit.com/ddd
  • 88. I could do an ML demo here But I won't!
  • 89. What can we learn from ML? • Consistent model (again) • Expression-based (again) – Everything is composable – Also prevents bugs • Type inference is awesome • Sensible defaults make accidents harder – E.g. immutable by default • Algebraic types are awesome
  • 91. I
  • 92. Is a simulation of a teletype really the best interface for interacting with an operating system? -- @gambler on HN, Jan 2019
  • 93. Smalltalk background • Developed at Xerox PARC – Along with the first PC, the first GUI, the first laser printer, ethernet, and more. • Smalltalk introduced – Message-based OO – Model-View-Controller – A windowing IDE – Also had aVM, generational GC, etc.
  • 95. Learning from Smalltalk #1: A consistent model: everything is an object everything is an object everything is an object everything is an object
  • 96. Learning from Smalltalk #2: Minimal syntax
  • 97. Learning from Smalltalk #2: Minimal syntax Put the power in the language instead.
  • 98. Learning from Smalltalk #2: Minimal syntax Put the power in the language instead.
  • 99. Learning from Smalltalk #3: Late binding If you're going to be a dynamic language, be a really dynamic language.
  • 100. Learning from Smalltalk #4: Who needs text files? If everything is accessible you have a lot of power
  • 102. What can we learn from Smalltalk? • A consistent model, again • Minimize syntax and make the language powerful • Be awesome and make people fall in love with you!
  • 104. What can we learn from the 1970's? • Many great ideas were developed 40 years ago – They should be more widely known • There are many different approaches to solving problems. – A bigger toolbox is a good thing to have – Use the right tool for the job
  • 105. And one more thing… C-style syntax is not the only possible syntax! – No curly braces – Sentences can end properly, with a period! – No dot syntax (not even in OO Smalltalk)
  • 106. "A language that doesn't affect the way you think about programming, is not worth knowing" – Alan Perlis So go forth and expand your Galaxy Brain!
  • 107. Slides and video here fsharpforfunandprofit.com/fourfromforty Thank you! "Domain modelling Made Functional" book fsharpforfunandprofit.com/books @ScottWlaschin Me on twitter