8. PROCEDURAL
BASIC and C are the most notable
languages here
Gave us basic looping constructs and
subroutines
Why?
To abstract away from GOTO
statements
8
12. DEFINITION
A style of building the structure and
elements of computer programs, that treats
computation as the evaluation of
mathematical functions and avoids state
and mutable data
12http://en.wikipedia.org/wiki/Functional_programming
27. IMPURE
27
var numbers = [1, 2, 3, 4, 5];
var destination = [];
for(var i = 0; i < numbers.length; i++) {
var result = numbers[i] * 2;
destination.push(result);
}
//destination => [2, 4, 6, 8, 10]
28. MAP (HIGHER ORDER FUNCTION)
Map is the name of a higher-order function
that applies a given function to each
element of a list, returning a list of results
28
29. FILTER (HIGHER ORDER FUNCTION)
Filter is a higher-order function that
processes a collection to produce a new
collection containing exactly those elements
of the original collection for which a given
predicate returns true
29
30. FOLD / REDUCE / AGGREGATE
A family of higher-order functions that
analyse a recursive data structure and
recombine through use of a given combining
operation the results of recursively
processing its constituent parts, building up
a return value
30
33. WHAT IS THIS DOING!?!
33
var n = 1;
var num_elements = 0;
var sum_of_first_10 = 0;
while (num_elements < 10) {
if (n^2 % 5 == 0) {
sum_of_first_10 += n;
num_elements += 1;
}
n += 1;
}
//sum_of_first_10 => 225
64. WHY?
64
Concurrency is hugely important with multi-
core processors
Simplicity - data sharing across threads and
processes is hard if it’s mutable
65. YOU CAN DO THIS IN ANY LANGUAGE!!!!
▫︎Try to write pure small pure methods/functions
▫︎Avoid state wherever you can
▫︎Separate impurities when they can’t be removed
▫︎Create immutable classes (value objects)
▫︎Look at simpler methods for concurrency
65