SlideShare une entreprise Scribd logo
1  sur  76
Télécharger pour lire hors ligne
Functional
Programming
You
Already
Know
@KevlinHenney
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)
#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');
}
/* 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;
}
http://www.adampetersen.se/articles/fizzbuzz.htm
http://www.adampetersen.se/articles/fizzbuzz.htm
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);
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"
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());
William Cook, "On Understanding Data Abstraction, Revisited"
newStack =
  (let items = ref() 
{
isEmpty =   #items = 0,
depth =   #items,
push =  x  items := xˆitemsy  y  0...#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]
}
}
}
intension, n. (Logic)
 the set of characteristics or properties by which
the referent or referents of a given expression is
determined; the sense of an expression that
determines its reference in every possible world,
as opposed to its actual reference. For example,
the intension of prime number may be having
non-trivial integral factors, whereas its extension
would be the set {2, 3, 5, 7, ...}.
E J Borowski and J M Borwein
Dictionary of Mathematics
A list comprehension is a syntactic
construct available in some programming
languages for creating a list based on
existing lists. It follows the form of the
mathematical set-builder notation (set
comprehension) as distinct from the use of
map and filter functions.
http://en.wikipedia.org/wiki/List_comprehension
{ 2  x | x  , x > 0 }
(2 * x for x in count() if x > 0)
{ x | x  , x > 0  x mod 2 = 0 }
(x for x in count() if x > 0 and x % 2 == 0)
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
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 final 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 final 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() ...
...
}
Immutable Value
Define a value object type
whose instances are immutable.
Copied Value
Define a value object type
whose instances are copyable.
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.
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"
OOP to me means only
messaging, local retention
and protection and hiding of
state-process, and extreme
late-binding of all things.
Alan Kay
The makefile language is similar to
declarative programming. This class
of language, in which necessary end
conditions are described but the
order in which actions are to be
taken is not important, is sometimes
confusing to programmers used to
imperative programming.
http://en.wikipedia.org/wiki/Make_(software)
SELECT time, speaker, title
FROM Sessions
WHERE
date = '2013-06-13' AND
time >= '11:40:00'
ORDER BY time
try {
Integer.parseInt(time.substring(0, 2));
}
catch (Exception x) {
return false;
}
if (Integer.parseInt(time.substring(0, 2)) > 12) {
return false;
}
...
if (!time.substring(9, 11).equals("AM") &
!time.substring(9, 11).equals("PM")) {
return false;
}
Burk Hufnagel
"Put the Mouse Down and Step Away from the Keyboard"
97 Things Every Programmer Should Know
public static boolean validateTime(String time) {
return time.matches("(0[1-9]|1[0-2]):[0-5][0-9]:[0-5][0-9] ([AP]M)");
}
Burk Hufnagel
"Put the Mouse Down and Step Away from the Keyboard"
97 Things Every Programmer Should Know
$0 % 3 == 0 { printf "Fizz" }
$0 % 5 == 0 { printf "Buzz" }
$0 % 3 != 0 && $0 % 5 != 0 { printf $0 }
{ printf "n" }
echo {1..100} | tr ' ' 'n' | awk '
$0 % 3 == 0 { printf "Fizz" }
$0 % 5 == 0 { printf "Buzz" }
$0 % 3 != 0 && $0 % 5 != 0 { printf $0 }
{ printf "n" }
'
echo {1..100} | tr ' ' 'n' | awk '
$0 % 3 == 0 { printf "Fizz" }
$0 % 5 == 0 { printf "Buzz" }
$0 % 3 != 0 && $0 % 5 != 0 { printf $0 }
{ printf "n" }
' | diff - expected && echo Pass
/^1?$|^(11+?)1+$/
http://www.noulakaz.net/weblog/2007/03/18/
a-regular-expression-to-check-for-prime-numbers/
def is_prime(n)
("1" * n) !~ /^1?$|^(11+?)1+$/
end
http://xkcd.com/224/
We lost the documentation on quantum mechanics.
You'll have to decode the regexes yourself.

Contenu connexe

Tendances

07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and MapsIntro C# Book
 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersEelco Visser
 
Pointcuts and Analysis
Pointcuts and AnalysisPointcuts and Analysis
Pointcuts and AnalysisWiwat Ruengmee
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingEelco Visser
 
julia-Latest Programming language
julia-Latest Programming  languagejulia-Latest Programming  language
julia-Latest Programming languageNithya Prakasan
 
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Ontico
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queuesIntro C# Book
 
Object Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & DestructorsObject Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & DestructorsDudy Ali
 
15. Streams Files and Directories
15. Streams Files and Directories 15. Streams Files and Directories
15. Streams Files and Directories Intro C# Book
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlowOswald Campesato
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language ComparisonRobert Bachmann
 
DeepStochLog: Neural Stochastic Logic Programming
DeepStochLog: Neural Stochastic Logic ProgrammingDeepStochLog: Neural Stochastic Logic Programming
DeepStochLog: Neural Stochastic Logic ProgrammingThomas Winters
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comShwetaAggarwal56
 

Tendances (20)

07. Java Array, Set and Maps
07.  Java Array, Set and Maps07.  Java Array, Set and Maps
07. Java Array, Set and Maps
 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | Interpreters
 
Pointcuts and Analysis
Pointcuts and AnalysisPointcuts and Analysis
Pointcuts and Analysis
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Chapter 2 Java Methods
Chapter 2 Java MethodsChapter 2 Java Methods
Chapter 2 Java Methods
 
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
 
julia-Latest Programming language
julia-Latest Programming  languagejulia-Latest Programming  language
julia-Latest Programming language
 
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)Kotlin Perfomance on Android / Александр Смирнов (Splyt)
Kotlin Perfomance on Android / Александр Смирнов (Splyt)
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
 
Python advance
Python advancePython advance
Python advance
 
Object Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & DestructorsObject Oriented Programming - Constructors & Destructors
Object Oriented Programming - Constructors & Destructors
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
15. Streams Files and Directories
15. Streams Files and Directories 15. Streams Files and Directories
15. Streams Files and Directories
 
Linked list
Linked listLinked list
Linked list
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlow
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language Comparison
 
DeepStochLog: Neural Stochastic Logic Programming
DeepStochLog: Neural Stochastic Logic ProgrammingDeepStochLog: Neural Stochastic Logic Programming
DeepStochLog: Neural Stochastic Logic Programming
 
Python for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.comPython for data science by www.dmdiploma.com
Python for data science by www.dmdiploma.com
 
Memory Management In C++
Memory Management In C++Memory Management In C++
Memory Management In C++
 
Clojure 7-Languages
Clojure 7-LanguagesClojure 7-Languages
Clojure 7-Languages
 

En vedette

Intelligent soft computing based
Intelligent soft computing basedIntelligent soft computing based
Intelligent soft computing basedijasa
 
Dry film thickness by ultrasonication meter
Dry film thickness by ultrasonication meterDry film thickness by ultrasonication meter
Dry film thickness by ultrasonication meterVISHNU SHARMA
 
The Architecture of Uncertainty
The Architecture of UncertaintyThe Architecture of Uncertainty
The Architecture of UncertaintyKevlin Henney
 
Uncertainty Problem in Control & Decision Theory
Uncertainty Problem in Control & Decision TheoryUncertainty Problem in Control & Decision Theory
Uncertainty Problem in Control & Decision TheorySSA KPI
 
Representing uncertainty in expert systems
Representing uncertainty in expert systemsRepresenting uncertainty in expert systems
Representing uncertainty in expert systemsbhupendra kumar
 
New paradigm in hr &amp; new 'measurement' methods
New paradigm in hr &amp; new 'measurement' methodsNew paradigm in hr &amp; new 'measurement' methods
New paradigm in hr &amp; new 'measurement' methodsElif Kuş Saillard
 
Managing Uncertainty to Improve Decision Making - Statistical Thinking for Qu...
Managing Uncertainty to Improve Decision Making - Statistical Thinking for Qu...Managing Uncertainty to Improve Decision Making - Statistical Thinking for Qu...
Managing Uncertainty to Improve Decision Making - Statistical Thinking for Qu...Prof. Dr. Diego Kuonen
 
Sources of uncertainty in the organizational environment
Sources of uncertainty in the organizational environmentSources of uncertainty in the organizational environment
Sources of uncertainty in the organizational environmentPrayag Ram
 
soft-computing
 soft-computing soft-computing
soft-computingstudent
 
Introduction to soft computing
Introduction to soft computingIntroduction to soft computing
Introduction to soft computingAnkush Kumar
 

En vedette (12)

Intelligent soft computing based
Intelligent soft computing basedIntelligent soft computing based
Intelligent soft computing based
 
Dry film thickness by ultrasonication meter
Dry film thickness by ultrasonication meterDry film thickness by ultrasonication meter
Dry film thickness by ultrasonication meter
 
The Architecture of Uncertainty
The Architecture of UncertaintyThe Architecture of Uncertainty
The Architecture of Uncertainty
 
Uncertainty Problem in Control & Decision Theory
Uncertainty Problem in Control & Decision TheoryUncertainty Problem in Control & Decision Theory
Uncertainty Problem in Control & Decision Theory
 
Representing uncertainty in expert systems
Representing uncertainty in expert systemsRepresenting uncertainty in expert systems
Representing uncertainty in expert systems
 
New paradigm in hr &amp; new 'measurement' methods
New paradigm in hr &amp; new 'measurement' methodsNew paradigm in hr &amp; new 'measurement' methods
New paradigm in hr &amp; new 'measurement' methods
 
Managing Uncertainty to Improve Decision Making - Statistical Thinking for Qu...
Managing Uncertainty to Improve Decision Making - Statistical Thinking for Qu...Managing Uncertainty to Improve Decision Making - Statistical Thinking for Qu...
Managing Uncertainty to Improve Decision Making - Statistical Thinking for Qu...
 
Sources of uncertainty in the organizational environment
Sources of uncertainty in the organizational environmentSources of uncertainty in the organizational environment
Sources of uncertainty in the organizational environment
 
soft-computing
 soft-computing soft-computing
soft-computing
 
Introduction to soft computing
Introduction to soft computingIntroduction to soft computing
Introduction to soft computing
 
Soft computing
Soft computingSoft computing
Soft computing
 
Exploring Sources of Uncertainties in Solar Resource Measurements
Exploring Sources of Uncertainties in Solar Resource MeasurementsExploring Sources of Uncertainties in Solar Resource Measurements
Exploring Sources of Uncertainties in Solar Resource Measurements
 

Similaire à Functional Programming You Already Know

Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Codemotion
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойSigma Software
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptxGuy Komari
 
Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mark Needham
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)Pavlo Baron
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and MonoidsHugo Gävert
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingRichardWarburton
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 

Similaire à Functional Programming You Already Know (20)

Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
Lezione03
Lezione03Lezione03
Lezione03
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
 
Functions
FunctionsFunctions
Functions
 
Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#
 
Chapter 02 functions -class xii
Chapter 02   functions -class xiiChapter 02   functions -class xii
Chapter 02 functions -class xii
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Python basic
Python basicPython basic
Python basic
 
Java
JavaJava
Java
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and Monoids
 
Lecture 12 os
Lecture 12 osLecture 12 os
Lecture 12 os
 
Interpreter Case Study - Design Patterns
Interpreter Case Study - Design PatternsInterpreter Case Study - Design Patterns
Interpreter Case Study - Design Patterns
 
C# programming
C# programming C# programming
C# programming
 
Twins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional ProgrammingTwins: Object Oriented Programming and Functional Programming
Twins: Object Oriented Programming and Functional Programming
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 

Plus de Kevlin Henney

The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical ExcellenceKevlin Henney
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical DevelopmentKevlin Henney
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid DeconstructionKevlin Henney
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayKevlin Henney
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test CasesKevlin Henney
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to ImmutabilityKevlin Henney
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-InKevlin Henney
 
Giving Code a Good Name
Giving Code a Good NameGiving Code a Good Name
Giving Code a Good NameKevlin Henney
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Kevlin Henney
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantKevlin Henney
 

Plus de Kevlin Henney (20)

Program with GUTs
Program with GUTsProgram with GUTs
Program with GUTs
 
The Case for Technical Excellence
The Case for Technical ExcellenceThe Case for Technical Excellence
The Case for Technical Excellence
 
Empirical Development
Empirical DevelopmentEmpirical Development
Empirical Development
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Solid Deconstruction
Solid DeconstructionSolid Deconstruction
Solid Deconstruction
 
Get Kata
Get KataGet Kata
Get Kata
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
 
Structure and Interpretation of Test Cases
Structure and Interpretation of Test CasesStructure and Interpretation of Test Cases
Structure and Interpretation of Test Cases
 
Agility ≠ Speed
Agility ≠ SpeedAgility ≠ Speed
Agility ≠ Speed
 
Refactoring to Immutability
Refactoring to ImmutabilityRefactoring to Immutability
Refactoring to Immutability
 
Old Is the New New
Old Is the New NewOld Is the New New
Old Is the New New
 
Turning Development Outside-In
Turning Development Outside-InTurning Development Outside-In
Turning Development Outside-In
 
Giving Code a Good Name
Giving Code a Good NameGiving Code a Good Name
Giving Code a Good Name
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
 
Thinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation QuadrantThinking Outside the Synchronisation Quadrant
Thinking Outside the Synchronisation Quadrant
 
Code as Risk
Code as RiskCode as Risk
Code as Risk
 
Software Is Details
Software Is DetailsSoftware Is Details
Software Is Details
 
Game of Sprints
Game of SprintsGame of Sprints
Game of Sprints
 
Good Code
Good CodeGood Code
Good Code
 

Dernier

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
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 Modelsaagamshah0812
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
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 WorkerThousandEyes
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
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 GoalsJhone kinadey
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
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.jsAndolasoft Inc
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
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 PrecisionSolGuruz
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
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 ApplicationsAlberto González Trastoy
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Dernier (20)

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
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
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
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
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
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
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
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
 
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
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
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
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

Functional Programming You Already Know

  • 2.
  • 3.
  • 4.
  • 5.
  • 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
  • 15.
  • 16.
  • 17. #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'); }
  • 18.
  • 19. /* 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; }
  • 20.
  • 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.
  • 27. 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"
  • 28. public class HeatingSystem { public void turnOn()  public void turnOff()   } public class Timer { public Timer(TimeOfDay toExpire, Runnable toDo)  public void run()  public void cancel()   }
  • 29. Timer on = new Timer( timeToTurnOn, new Runnable() { public void run() { heatingSystem.turnOn(); } }); Timer off = new Timer( timeToTurnOff, new Runnable() { public void run() { heatingSystem.turnOff(); } });
  • 30. class Timer { public: Timer(TimeOfDay toExpire, function<void()> toDo); void run(); void cancel(); ... };
  • 31. Timer on( timeOn, bind(&HeatingSystem::turnOn, &heatingSystem)); Timer off( timeOff, bind(&HeatingSystem::turnOff, &heatingSystem));
  • 32. public class Timer { public Timer(TimeOfDay toExpire, Action toDo) ... public void Run() ... public void Cancel() ... ... }
  • 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. William Cook, "On Understanding Data Abstraction, Revisited"
  • 36. newStack =   (let items = ref()  { isEmpty =   #items = 0, depth =   #items, push =  x  items := xˆitemsy  y  0...#items, top =   items0 })
  • 37. 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] } } }
  • 38. intension, n. (Logic)  the set of characteristics or properties by which the referent or referents of a given expression is determined; the sense of an expression that determines its reference in every possible world, as opposed to its actual reference. For example, the intension of prime number may be having non-trivial integral factors, whereas its extension would be the set {2, 3, 5, 7, ...}. E J Borowski and J M Borwein Dictionary of Mathematics
  • 39. A list comprehension is a syntactic construct available in some programming languages for creating a list based on existing lists. It follows the form of the mathematical set-builder notation (set comprehension) as distinct from the use of map and filter functions. http://en.wikipedia.org/wiki/List_comprehension
  • 40. { 2  x | x  , x > 0 }
  • 41. (2 * x for x in count() if x > 0)
  • 42. { x | x  , x > 0  x mod 2 = 0 }
  • 43. (x for x in count() if x > 0 and x % 2 == 0)
  • 44.
  • 45. 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
  • 47. (f ○ g ○ h)(x)
  • 48. x h g f
  • 49. h | g | f
  • 50. 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
  • 51.
  • 52. find . -name "*.java" | sed 's/.*///' | sort | uniq -c | grep -v "^ *1 " | sort -r Heinz Kabutz "Know Your IDE" 97 Things Every Programmer Should Know
  • 56. 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
  • 57. public final 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) ... ... }
  • 58. public final 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) ... ... }
  • 59. public final class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getWeekInYear() ... public int getDayInYear() ... public int getDayInMonth() ... public int getDayInWeek() ... ... }
  • 60. When it is not necessary to change, it is necessary not to change. Lucius Cary
  • 61. public final class Date implements ... { ... public int getYear() ... public int getMonth() ... public int getWeekInYear() ... public int getDayInYear() ... public int getDayInMonth() ... public int getDayInWeek() ... ... }
  • 62. public final class Date implements ... { ... public int year() ... public int month() ... public int weekInYear() ... public int dayInYear() ... public int dayInMonth() ... public int dayInWeek() ... ... }
  • 63. Immutable Value Define a value object type whose instances are immutable. Copied Value Define a value object type whose instances are copyable.
  • 64.
  • 65. 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. 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.
  • 67. OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. Alan Kay
  • 68. The makefile language is similar to declarative programming. This class of language, in which necessary end conditions are described but the order in which actions are to be taken is not important, is sometimes confusing to programmers used to imperative programming. http://en.wikipedia.org/wiki/Make_(software)
  • 69. SELECT time, speaker, title FROM Sessions WHERE date = '2013-06-13' AND time >= '11:40:00' ORDER BY time
  • 70. try { Integer.parseInt(time.substring(0, 2)); } catch (Exception x) { return false; } if (Integer.parseInt(time.substring(0, 2)) > 12) { return false; } ... if (!time.substring(9, 11).equals("AM") & !time.substring(9, 11).equals("PM")) { return false; } Burk Hufnagel "Put the Mouse Down and Step Away from the Keyboard" 97 Things Every Programmer Should Know
  • 71. public static boolean validateTime(String time) { return time.matches("(0[1-9]|1[0-2]):[0-5][0-9]:[0-5][0-9] ([AP]M)"); } Burk Hufnagel "Put the Mouse Down and Step Away from the Keyboard" 97 Things Every Programmer Should Know
  • 72. $0 % 3 == 0 { printf "Fizz" } $0 % 5 == 0 { printf "Buzz" } $0 % 3 != 0 && $0 % 5 != 0 { printf $0 } { printf "n" }
  • 73. echo {1..100} | tr ' ' 'n' | awk ' $0 % 3 == 0 { printf "Fizz" } $0 % 5 == 0 { printf "Buzz" } $0 % 3 != 0 && $0 % 5 != 0 { printf $0 } { printf "n" } '
  • 74. echo {1..100} | tr ' ' 'n' | awk ' $0 % 3 == 0 { printf "Fizz" } $0 % 5 == 0 { printf "Buzz" } $0 % 3 != 0 && $0 % 5 != 0 { printf $0 } { printf "n" } ' | diff - expected && echo Pass
  • 76. http://xkcd.com/224/ We lost the documentation on quantum mechanics. You'll have to decode the regexes yourself.