SlideShare a Scribd company logo
ROME 27-28 march 2015
functional programming
you already know
@KevlinHenney
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
functional
programming
higher-order functions
recursion
statelessness
first-class functions
immutability
pure functions
unification
declarative
pattern matching
non-strict evaluation
idempotence
lists
mathematics
lambdas
currying
monads
Excel is the world's
most popular
functional language.
Simon Peyton Jones
To iterate is human,
to recurse divine.
L Peter Deutsch
int factorial(int n)
{
int result = 1;
while(n > 1)
result *= n--;
return result;
}
int factorial(int n)
{
if(n > 1)
return n * factorial(n - 1);
else
return 1;
}
int factorial(int n)
{
return
n > 1
? n * factorial(n - 1)
: 1;
}
n! =
1
(n – 1)!  n
if n = 0,
if n > 0.{
n! =
n
k = 1
k
seriesProduct(k, k, 1, n)
reduce(
int.__mul__,
range(1, n+1), 1)
reduce(
lambda l, r: l*r,
range(1, n+1), 1)
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
#include <stdio.h>
/* printd: print n in decimal */
void printd(int n)
{
if (n < 0) {
putchar('-');
n = -n;
}
if (n / 10)
printd(n / 10);
putchar(n % 10 + '0');
}
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
/* grep: search for regexp in file */
int grep(char *regexp, FILE *f, char *name)
{
int n, nmatch;
char buf[BUFSIZ];
nmatch = 0;
while (fgets(buf, sizeof buf, f) != NULL) {
n = strlen(buf);
if (n > 0 && buf[n-1] == 'n')
buf[n-1] = '0';
if (match(regexp, buf)) {
nmatch++;
if (name != NULL)
printf("%s:", name);
printf("%sn", buf);
}
}
return nmatch;
}
/* matchhere: search for regexp at beginning of text */
int matchhere(char *regexp, char *text)
{
if (regexp[0] == '0')
return 1;
if (regexp[1] == '*')
return matchstar(regexp[0], regexp+2, text);
if (regexp[0] == '$' && regexp[1] == '0')
return *text == '0';
if (*text!='0' && (regexp[0]=='.' || regexp[0]==*text))
return matchhere(regexp+1, text+1);
return 0;
}
/* match: search for regexp anywhere in text */
int match(char *regexp, char *text)
{
if (regexp[0] == '^')
return matchhere(regexp+1, text);
do { /* must look even if string is empty */
if (matchhere(regexp, text))
return 1;
} while (*text++ != '0');
return 0;
}
/* matchstar: search for c*regexp at beginning of text */
int matchstar(int c, char *regexp, char *text)
{
do { /* a * matches zero or more instances */
if (matchhere(regexp, text))
return 1;
} while (*text != '0' && (*text++ == c || c == '.'));
return 0;
}
int atexit(void (*func)(void));
void qsort(
void *base,
size_t nmemb, size_t size,
int (*compar)(
const void *, const void *));
void (*signal(
int sig, void (*func)(int)))(int);
Use procedure arguments to provide
flexibility in an interface.
This technique can greatly simplify
an interface, eliminating a jumble of
parameters that amount to a small
programming language.
Butler W Lampson
"Hints for Computer System Design"
public class HeatingSystem
{
public void turnOn() 
public void turnOff() 

}
public class Timer
{
public Timer(TimeOfDay toExpire, Runnable toDo) 
public void run() 
public void cancel() 

}
Timer on =
new Timer(
timeToTurnOn,
new Runnable()
{
public void run()
{
heatingSystem.turnOn();
}
});
Timer off =
new Timer(
timeToTurnOff,
new Runnable()
{
public void run()
{
heatingSystem.turnOff();
}
});
class Timer
{
public:
Timer(TimeOfDay toExpire, function<void()> toDo);
void Run();
void Cancel();
...
};
Timer on(
timeOn,
bind(&HeatingSystem::TurnOn, &heatingSystem));
Timer off(
timeOff,
bind(&HeatingSystem::TurnOff, &heatingSystem));
public class Timer
{
public Timer(TimeOfDay toExpire, Action toDo) ...
public void Run() ...
public void Cancel() ...
...
}
Timer on = new Timer(timeOn, heatingSystem.TurnOn);
Timer off = new Timer(timeOff, heatingSystem.TurnOff);
Timer on = new Timer(timeOn, heatingSystem::turnOn);
Timer off = new Timer(timeOff, heatingSystem::turnOff);
Timer on =
new Timer(timeOn, () => heatingSystem.TurnOn());
Timer off =
new Timer(timeOff, () => heatingSystem.TurnOff());
Timer on =
new Timer(timeOn, () -> heatingSystem.turnOn());
Timer off =
new Timer(timeOff, () -> heatingSystem.turnOff());
Timer on(
timeOn, [&]() { heatingSystem.TurnOn(); });
Timer off(
timeOff, [&]() { heatingSystem.TurnOff(); });
William Cook, "On Understanding Data Abstraction, Revisited"
newStack =
  (let items = ref() 
{
isEmpty =   #items = 0,
depth =   #items,
push =  x  items := xˆitems,
top =   items0
})
var newStack = function() {
var items = []
return {
isEmpty: function() {
return items.length === 0
},
depth: function() {
return items.length
},
push: function(newTop) {
items = items.unshift(newTop)
},
top: function() {
return items[0]
}
}
}
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
One of the most powerful mechanisms
for program structuring [...] is the block
and procedure concept.
A procedure which is capable of giving
rise to block instances which survive its
call will be known as a class; and the
instances will be known as objects of
that class.
A call of a class generates a new object
of that class.
Ole-Johan Dahl and C A R Hoare
"Hierarchical Program Structures"
Concatenative programming is so called
because it uses function composition instead of
function application—a non-concatenative
language is thus called applicative.
Jon Purdy
http://evincarofautumn.blogspot.in/2012/02/
why-concatenative-programming-matters.html
f(g(h(x)))
(f ○ g ○ h)(x)
x h g f
h | g | f
This is the basic reason Unix pipes are so
powerful: they form a rudimentary string-based
concatenative programming language.
Jon Purdy
http://evincarofautumn.blogspot.in/2012/02/
why-concatenative-programming-matters.html
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
find . -name "*.java" |
sed 's/.*///' |
sort |
uniq -c |
grep -v "^ *1 " |
sort -r
Heinz Kabutz
"Know Your IDE"
97 Things Every Programmer Should Know
Concurrency
Concurrency
Threads
Concurrency
Threads
Locks
Some people, when confronted with a
problem, think, "I know, I'll use threads,"
and then two they hav erpoblesms.
Ned Batchelder
https://twitter.com/#!/nedbat/status/194873829825327104
public class Date implements ...
{
...
public int getYear() ...
public int getMonth() ...
public int getDayInMonth() ...
public void setYear(int newYear) ...
public void setMonth(int newMonth) ...
public void setDayInMonth(int newDayInMonth) ...
...
}
public class Date implements ...
{
...
public int getYear() ...
public int getMonth() ...
public int getWeekInYear() ...
public int getDayInYear() ...
public int getDayInMonth() ...
public int getDayInWeek() ...
public void setYear(int newYear) ...
public void setMonth(int newMonth) ...
public void setWeekInYear(int newWeek) ...
public void setDayInYear(int newDayInYear) ...
public void setDayInMonth(int newDayInMonth) ...
public void setDayInWeek(int newDayInWeek) ...
...
}
public final class Date implements ...
{
...
public int getYear() ...
public int getMonth() ...
public int getWeekInYear() ...
public int getDayInYear() ...
public int getDayInMonth() ...
public int getDayInWeek() ...
...
}
When it is not
necessary to
change, it is
necessary not
to change.
Lucius Cary
public final class Date implements ...
{
...
public int getYear() ...
public int getMonth() ...
public int getWeekInYear() ...
public int getDayInYear() ...
public int getDayInMonth() ...
public int getDayInWeek() ...
...
}
public final class Date implements ...
{
...
public int year() ...
public int month() ...
public int weekInYear() ...
public int dayInYear() ...
public int dayInMonth() ...
public int dayInWeek() ...
...
}
Mutable
Immutable
Unshared Shared
Unshared mutable
data needs no
synchronisation
Unshared immutable
data needs no
synchronisation
Shared mutable
data needs
synchronisation
Shared immutable
data needs no
synchronisation
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Instead of using threads and shared memory
as our programming model, we can use
processes and message passing. Process here
just means a protected independent state
with executing code, not necessarily an
operating system process.
Russel Winder
"Message Passing Leads to Better Scalability in Parallel Systems"
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.
Alan Kay
Languages such as Erlang (and occam before
it) have shown that processes are a very
successful mechanism for programming
concurrent and parallel systems. Such
systems do not have all the synchronization
stresses that shared-memory, multithreaded
systems have.
Russel Winder
"Message Passing Leads to Better Scalability in Parallel Systems"
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
http://xkcd.com/224/
We lost the documentation on quantum mechanics.
You'll have to decode the regexes yourself.

More Related Content

PDF
Solid Deconstruction
PDF
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
PDF
Object-oriented Programming in Python
PPTX
Chapter 05 classes and objects
PPTX
Chapter 06 constructors and destructors
PDF
SOLID Deconstruction
DOCX
Python Interview Questions For Experienced
DOCX
Java Interview Questions For Freshers
Solid Deconstruction
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Object-oriented Programming in Python
Chapter 05 classes and objects
Chapter 06 constructors and destructors
SOLID Deconstruction
Python Interview Questions For Experienced
Java Interview Questions For Freshers

What's hot (20)

PPTX
CLASS OBJECT AND INHERITANCE IN PYTHON
PPTX
Chapter 07 inheritance
PPT
Generics in java
PDF
C++ Object oriented concepts & programming
PDF
Java q ref 2018
PDF
Wrapper classes
PDF
Lazy java
PDF
Generics
PDF
Object oriented approach in python programming
PPTX
Python OOPs
PPTX
Class, object and inheritance in python
PDF
Programming in c++
PPT
Java Notes
PDF
Python Advanced – Building on the foundation
PPTX
Learn Concept of Class and Object in C# Part 3
PDF
Python Programming - VI. Classes and Objects
PDF
Object-oriented Programming-with C#
PPT
Oop java
PPTX
class and objects
PDF
OOP and FP
CLASS OBJECT AND INHERITANCE IN PYTHON
Chapter 07 inheritance
Generics in java
C++ Object oriented concepts & programming
Java q ref 2018
Wrapper classes
Lazy java
Generics
Object oriented approach in python programming
Python OOPs
Class, object and inheritance in python
Programming in c++
Java Notes
Python Advanced – Building on the foundation
Learn Concept of Class and Object in C# Part 3
Python Programming - VI. Classes and Objects
Object-oriented Programming-with C#
Oop java
class and objects
OOP and FP
Ad

Similar to Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015 (20)

PDF
Functional Programming You Already Know
PPTX
Data structures
PPTX
Столпы функционального программирования для адептов ООП, Николай Мозговой
ODP
Interview questions slide deck
PDF
Functional programming in C++
PPTX
Why functional programming in C# & F#
PDF
Functional programming
PPT
Queue (1)(1).ppt
PPTX
U3.stack queue
PDF
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
PPTX
هياكلبيانات
PDF
Functional C++
PDF
Dimitry Solovyov - The imminent threat of functional programming
PPTX
Functional Paradigm.pptx
DOCX
Example PseudocodeProblem Given a sorted array a with n elements .docx
PPTX
Functional Programming Fundamentals
PDF
Data Structure - Lecture 2 - Recursion Stack Queue.pdf
PPT
Data structure and algorithm first chapter
PPT
PDF
Software Engineering
Functional Programming You Already Know
Data structures
Столпы функционального программирования для адептов ООП, Николай Мозговой
Interview questions slide deck
Functional programming in C++
Why functional programming in C# & F#
Functional programming
Queue (1)(1).ppt
U3.stack queue
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
هياكلبيانات
Functional C++
Dimitry Solovyov - The imminent threat of functional programming
Functional Paradigm.pptx
Example PseudocodeProblem Given a sorted array a with n elements .docx
Functional Programming Fundamentals
Data Structure - Lecture 2 - Recursion Stack Queue.pdf
Data structure and algorithm first chapter
Software Engineering
Ad

More from Codemotion (20)

PDF
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
PDF
Pompili - From hero to_zero: The FatalNoise neverending story
PPTX
Pastore - Commodore 65 - La storia
PPTX
Pennisi - Essere Richard Altwasser
PPTX
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
PPTX
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
PPTX
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
PPTX
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
PDF
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
PDF
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
PDF
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
PDF
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
PDF
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
PDF
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
PPTX
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
PPTX
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
PDF
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
PDF
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
PDF
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
PDF
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Pompili - From hero to_zero: The FatalNoise neverending story
Pastore - Commodore 65 - La storia
Pennisi - Essere Richard Altwasser
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Big Data Technologies - Introduction.pptx
PPT
Teaching material agriculture food technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Advanced methodologies resolving dimensionality complications for autism neur...
sap open course for s4hana steps from ECC to s4
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectral efficient network and resource selection model in 5G networks
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Empathic Computing: Creating Shared Understanding
20250228 LYD VKU AI Blended-Learning.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
Teaching material agriculture food technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015

  • 1. ROME 27-28 march 2015 functional programming you already know @KevlinHenney
  • 6. functional programming higher-order functions recursion statelessness first-class functions immutability pure functions unification declarative pattern matching non-strict evaluation idempotence lists mathematics lambdas currying monads
  • 7. Excel is the world's most popular functional language. Simon Peyton Jones
  • 8. To iterate is human, to recurse divine. L Peter Deutsch
  • 9. int factorial(int n) { int result = 1; while(n > 1) result *= n--; return result; }
  • 10. int factorial(int n) { if(n > 1) return n * factorial(n - 1); else return 1; }
  • 11. int factorial(int n) { return n > 1 ? n * factorial(n - 1) : 1; }
  • 12. n! = 1 (n – 1)!  n if n = 0, if n > 0.{
  • 13. n! = n k = 1 k
  • 16. reduce( lambda l, r: l*r, range(1, n+1), 1)
  • 20. #include <stdio.h> /* printd: print n in decimal */ void printd(int n) { if (n < 0) { putchar('-'); n = -n; } if (n / 10) printd(n / 10); putchar(n % 10 + '0'); }
  • 22. /* grep: search for regexp in file */ int grep(char *regexp, FILE *f, char *name) { int n, nmatch; char buf[BUFSIZ]; nmatch = 0; while (fgets(buf, sizeof buf, f) != NULL) { n = strlen(buf); if (n > 0 && buf[n-1] == 'n') buf[n-1] = '0'; if (match(regexp, buf)) { nmatch++; if (name != NULL) printf("%s:", name); printf("%sn", buf); } } return nmatch; } /* matchhere: search for regexp at beginning of text */ int matchhere(char *regexp, char *text) { if (regexp[0] == '0') return 1; if (regexp[1] == '*') return matchstar(regexp[0], regexp+2, text); if (regexp[0] == '$' && regexp[1] == '0') return *text == '0'; if (*text!='0' && (regexp[0]=='.' || regexp[0]==*text)) return matchhere(regexp+1, text+1); return 0; } /* match: search for regexp anywhere in text */ int match(char *regexp, char *text) { if (regexp[0] == '^') return matchhere(regexp+1, text); do { /* must look even if string is empty */ if (matchhere(regexp, text)) return 1; } while (*text++ != '0'); return 0; } /* matchstar: search for c*regexp at beginning of text */ int matchstar(int c, char *regexp, char *text) { do { /* a * matches zero or more instances */ if (matchhere(regexp, text)) return 1; } while (*text != '0' && (*text++ == c || c == '.')); return 0; }
  • 24. void qsort( void *base, size_t nmemb, size_t size, int (*compar)( const void *, const void *));
  • 25. void (*signal( int sig, void (*func)(int)))(int);
  • 26. Use procedure arguments to provide flexibility in an interface. This technique can greatly simplify an interface, eliminating a jumble of parameters that amount to a small programming language. Butler W Lampson "Hints for Computer System Design"
  • 27. public class HeatingSystem { public void turnOn()  public void turnOff()   } public class Timer { public Timer(TimeOfDay toExpire, Runnable toDo)  public void run()  public void cancel()   }
  • 28. Timer on = new Timer( timeToTurnOn, new Runnable() { public void run() { heatingSystem.turnOn(); } }); Timer off = new Timer( timeToTurnOff, new Runnable() { public void run() { heatingSystem.turnOff(); } });
  • 29. class Timer { public: Timer(TimeOfDay toExpire, function<void()> toDo); void Run(); void Cancel(); ... };
  • 30. Timer on( timeOn, bind(&HeatingSystem::TurnOn, &heatingSystem)); Timer off( timeOff, bind(&HeatingSystem::TurnOff, &heatingSystem));
  • 31. public class Timer { public Timer(TimeOfDay toExpire, Action toDo) ... public void Run() ... public void Cancel() ... ... }
  • 32. Timer on = new Timer(timeOn, heatingSystem.TurnOn); Timer off = new Timer(timeOff, heatingSystem.TurnOff);
  • 33. Timer on = new Timer(timeOn, heatingSystem::turnOn); Timer off = new Timer(timeOff, heatingSystem::turnOff);
  • 34. Timer on = new Timer(timeOn, () => heatingSystem.TurnOn()); Timer off = new Timer(timeOff, () => heatingSystem.TurnOff());
  • 35. Timer on = new Timer(timeOn, () -> heatingSystem.turnOn()); Timer off = new Timer(timeOff, () -> heatingSystem.turnOff());
  • 36. Timer on( timeOn, [&]() { heatingSystem.TurnOn(); }); Timer off( timeOff, [&]() { heatingSystem.TurnOff(); });
  • 37. William Cook, "On Understanding Data Abstraction, Revisited"
  • 38. newStack =   (let items = ref()  { isEmpty =   #items = 0, depth =   #items, push =  x  items := xˆitems, top =   items0 })
  • 39. var newStack = function() { var items = [] return { isEmpty: function() { return items.length === 0 }, depth: function() { return items.length }, push: function(newTop) { items = items.unshift(newTop) }, top: function() { return items[0] } } }
  • 41. One of the most powerful mechanisms for program structuring [...] is the block and procedure concept. A procedure which is capable of giving rise to block instances which survive its call will be known as a class; and the instances will be known as objects of that class. A call of a class generates a new object of that class. Ole-Johan Dahl and C A R Hoare "Hierarchical Program Structures"
  • 42. Concatenative programming is so called because it uses function composition instead of function application—a non-concatenative language is thus called applicative. Jon Purdy http://evincarofautumn.blogspot.in/2012/02/ why-concatenative-programming-matters.html
  • 44. (f ○ g ○ h)(x)
  • 45. x h g f
  • 46. h | g | f
  • 47. This is the basic reason Unix pipes are so powerful: they form a rudimentary string-based concatenative programming language. Jon Purdy http://evincarofautumn.blogspot.in/2012/02/ why-concatenative-programming-matters.html
  • 49. find . -name "*.java" | sed 's/.*///' | sort | uniq -c | grep -v "^ *1 " | sort -r Heinz Kabutz "Know Your IDE" 97 Things Every Programmer Should Know
  • 53. Some people, when confronted with a problem, think, "I know, I'll use threads," and then two they hav erpoblesms. Ned Batchelder https://twitter.com/#!/nedbat/status/194873829825327104
  • 54. public class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getDayInMonth() ... public void setYear(int newYear) ... public void setMonth(int newMonth) ... public void setDayInMonth(int newDayInMonth) ... ... }
  • 55. public class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getWeekInYear() ... public int getDayInYear() ... public int getDayInMonth() ... public int getDayInWeek() ... public void setYear(int newYear) ... public void setMonth(int newMonth) ... public void setWeekInYear(int newWeek) ... public void setDayInYear(int newDayInYear) ... public void setDayInMonth(int newDayInMonth) ... public void setDayInWeek(int newDayInWeek) ... ... }
  • 56. public final class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getWeekInYear() ... public int getDayInYear() ... public int getDayInMonth() ... public int getDayInWeek() ... ... }
  • 57. When it is not necessary to change, it is necessary not to change. Lucius Cary
  • 58. public final class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getWeekInYear() ... public int getDayInYear() ... public int getDayInMonth() ... public int getDayInWeek() ... ... }
  • 59. public final class Date implements ... { ... public int year() ... public int month() ... public int weekInYear() ... public int dayInYear() ... public int dayInMonth() ... public int dayInWeek() ... ... }
  • 60. Mutable Immutable Unshared Shared Unshared mutable data needs no synchronisation Unshared immutable data needs no synchronisation Shared mutable data needs synchronisation Shared immutable data needs no synchronisation
  • 62. Instead of using threads and shared memory as our programming model, we can use processes and message passing. Process here just means a protected independent state with executing code, not necessarily an operating system process. Russel Winder "Message Passing Leads to Better Scalability in Parallel Systems"
  • 63. 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. Alan Kay
  • 64. Languages such as Erlang (and occam before it) have shown that processes are a very successful mechanism for programming concurrent and parallel systems. Such systems do not have all the synchronization stresses that shared-memory, multithreaded systems have. Russel Winder "Message Passing Leads to Better Scalability in Parallel Systems"
  • 66. http://xkcd.com/224/ We lost the documentation on quantum mechanics. You'll have to decode the regexes yourself.