functional programming for fun and profit

44
FUNCTIONAL PROGRAMMING function() { return [‘fun’,‘profit’]; } Monday, 28 October 13

Upload: jamesottaway

Post on 17-Dec-2014

362 views

Category:

Technology


1 download

DESCRIPTION

Rather than continually instructing a computer on how to get the job done, wouldn't it be so much easier if we simply had to explain what we wanted, and have the computer fill in the blanks for us? Functional programming gives us this ability through its focus and priority on functions, rather than variables and classes, which allows us to reduce coupling and complexity, giving us a more repeatable program. In this talk I'll explain my journey to understand, appreciate and leverage the power given to me by functional programming. See more at https://github.com/jamesottaway/decks

TRANSCRIPT

Page 1: Functional Programming for Fun and Profit

FUNCTIONALPROGRAMMING

function() { return [‘fun’,‘profit’];}

Monday, 28 October 13

Page 2: Functional Programming for Fun and Profit

James Ottaway

@jms_

Monday, 28 October 13

Page 3: Functional Programming for Fun and Profit

elevator pitch

Monday, 28 October 13

Page 4: Functional Programming for Fun and Profit

teaser examples

Monday, 28 October 13

Page 5: Functional Programming for Fun and Profit

(take 25 (squares-of (integers)))

Monday, 28 October 13

Page 6: Functional Programming for Fun and Profit

[‘1’,’2’,’3’,’4’].map(&:to_i).reduce(&:+)

Monday, 28 October 13

Page 7: Functional Programming for Fun and Profit

[1,2,3,4,5].filter(function(i) { return i % 2 == 0;});

Monday, 28 October 13

Page 8: Functional Programming for Fun and Profit

history

Monday, 28 October 13

Page 9: Functional Programming for Fun and Profit

lambda calculus

Monday, 28 October 13

Page 10: Functional Programming for Fun and Profit

declarative programming

Monday, 28 October 13

Page 11: Functional Programming for Fun and Profit

> how

Monday, 28 October 13

Page 12: Functional Programming for Fun and Profit

nested paradigmsMonday, 28 October 13

Page 13: Functional Programming for Fun and Profit

regex

Monday, 28 October 13

Page 14: Functional Programming for Fun and Profit

reactive programming

Monday, 28 October 13

Page 15: Functional Programming for Fun and Profit

domain specific languages

Monday, 28 October 13

Page 16: Functional Programming for Fun and Profit

functional programming

Monday, 28 October 13

Page 17: Functional Programming for Fun and Profit

languages

Monday, 28 October 13

Page 18: Functional Programming for Fun and Profit

concepts

Monday, 28 October 13

Page 19: Functional Programming for Fun and Profit

function() { }

Monday, 28 October 13

Page 20: Functional Programming for Fun and Profit

function counter() { var x = 0;

function increment(y) { x += y; console.log(x); }

return increment;}

closures

Monday, 28 October 13

Page 21: Functional Programming for Fun and Profit

first_counter = counter();second_counter = counter();

first_counter(1) // returns 1first_counter(2) // returns 3first_counter(3) // returns 6

second_counter(5) // returns 5second_counter(5) // returns 10second_counter(5) // returns 15

closures

Monday, 28 October 13

Page 22: Functional Programming for Fun and Profit

no side effects

Monday, 28 October 13

Page 23: Functional Programming for Fun and Profit

insanity

Monday, 28 October 13

Page 24: Functional Programming for Fun and Profit

ONE = 1;

add = lambda { |x, y| x + y}

addOne = lambda { |x| add[x, ONE]}

referential transparency

Monday, 28 October 13

Page 25: Functional Programming for Fun and Profit

require 'date'

opaque_millis = lambda { DateTime.now.strftime('%Q').to_i}

transparent_millis = lambda { |datetime| datetime.strftime('%Q').to_i}

referential transparency

Monday, 28 October 13

Page 26: Functional Programming for Fun and Profit

memoisation

Monday, 28 October 13

Page 27: Functional Programming for Fun and Profit

deforestationMonday, 28 October 13

Page 28: Functional Programming for Fun and Profit

state is inevitable

Monday, 28 October 13

Page 29: Functional Programming for Fun and Profit

recursion

Monday, 28 October 13

Page 30: Functional Programming for Fun and Profit

structure and interpretation of computer programs

Monday, 28 October 13

Page 31: Functional Programming for Fun and Profit

examples

Monday, 28 October 13

Page 32: Functional Programming for Fun and Profit

list comprehension

Monday, 28 October 13

Page 33: Functional Programming for Fun and Profit

source = [1,2,3,4,5]destination = []

for i in 0..source.length-1 do destination << source[i]*2end

return destination

Monday, 28 October 13

Page 34: Functional Programming for Fun and Profit

[1,2,3,4,5].map { |i| i * 2 }

Monday, 28 October 13

Page 35: Functional Programming for Fun and Profit

numbers = [1,2,3,4,5]x = 0

for i in 1..numbers.length-1 do x += numbers[i]end

return x

Monday, 28 October 13

Page 36: Functional Programming for Fun and Profit

[1,2,3,4,5].reduce { |acc, x| acc + x }

Monday, 28 October 13

Page 37: Functional Programming for Fun and Profit

[1,2,3,4,5].reduce(&:+)

Monday, 28 October 13

Page 38: Functional Programming for Fun and Profit

mobile app frameworks

Monday, 28 October 13

Page 39: Functional Programming for Fun and Profit

Monday, 28 October 13

Page 40: Functional Programming for Fun and Profit

programming with nothing

Monday, 28 October 13

Page 41: Functional Programming for Fun and Profit

reactive extensions

Monday, 28 October 13

Page 42: Functional Programming for Fun and Profit

github desktop clients

Monday, 28 October 13

Page 43: Functional Programming for Fun and Profit

go forth and prosper!

Monday, 28 October 13

Page 44: Functional Programming for Fun and Profit

thanks

Monday, 28 October 13