Functional Thinking
director / software architect NEAL FORD meme wrangler
® ThoughtWorks
[email protected] 2002 Summit Boulevard, Atlanta, GA 30319 nealford.com thoughtworks.com memeagora.blogspot.com @neal4d
1 a metaphor an essay a history lesson
2 3 4 new language: easy new paradigm: hard
5 “functional” is more a way of thinking than a tool set
6 Execution in the Kingdom of Nouns
Steve Yegge http://steve-yegge.blogspot.com/ 2006/03/execution-in-kingdom-of-nouns.html
7 v e r b s !
8 !
9 http://oreilly.com/news/languageposter_0504.html 1954 1957 1960 1965 1970 1975 1980 1985 1990 1995 2000 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011
PostScript level 3 PostScript level 3 PostScript PostScript level 2 PostScript level 3 v 3016 v 3017 1982 1992 september 11, 1996 OO Forth 2003 september 11, 2005 1987 Forth FIG-Forth Forth-83 ANS Forth ISO Forth 1968 1978 1983 1986 1997
Logo Object Logo Tcl Tcl/Tk Tcl/Tk 8.1 Tcl/Tk 8.2.3 Tcl/Tk 8.3 Tcl/Tk 8.4 Tcl/Tk 8.4.1 Tcl/Tk 8.4.2 Tcl/Tk 8.4.3 Tcl/Tk 8.4.4 Tcl/Tk 8.4.5 Tcl/Tk 8.4.6 Tcl/Tk 8.4.7 Tcl/Tk 8.4.8 Tcl/Tk 8.4.9 Tcl/Tk 8.4.11 Tcl/Tk 8.4.12 Tcl/Tk 8.4.13 Tcl/Tk 8.4.14 Tcl/Tk 8.4.15 Tcl/Tk 8.5 Tcl/Tk 8.5.5 Tcl/Tk 8.5.6 Tcl/Tk 8.5.7 Tcl/Tk 8.5.9 1968 1986 mid 1988 end 1988 april 1999 dec. 16, 1999 october 22, 2001 september 10, 2002 october 22, 2002 march 3, 2003 may 20, 2003 july 22, 2003 november 24, 2003 march 1, 2004 july 25, 2004 nov. 22, 2004 december 7, 2004 june 28, 2005 december 6, 2005 april 19, 2006 october 19, 2006 may 25, 2007 december 20, 2007 october 15, 2008 january 2009 april 15, 2009 september 8, 2010 FORTRAN IV Fortran 2000 FORTRAN I FORTRAN II FORTRAN III FORTRAN IV FORTRAN V Fortran 90 ISO Fortran 2003 Fortran 2008 FORTRAN (Fortran 66 ANS) (Fortran 77 ANSI) Fortran 95 ISO (draft) november 1954 october 1956 1957 end-1958 1962 1991 december 15, 1997 november 30, 2004 september 2010 1966 april 1978 A A+ september 30, 2002 Prolog Prolog II Prolog III 1988 1992 Prolog IV 1970 october 1982 1984 1997 J K Sharp APL 1990 1996 JOSS TELCOMP MUMPS MUMPS (ANSI) MUMPS (FIPS) MUMPS ISO M M ANSI Open M M ISO M ISO 1964 1965 1966 september 15, 1977 1986 1992 1994 dec 8, 1995 dec 11, 1995 1999 january 6, 2005 Modula 3 Delphi Delphi 5 Delphi 6 Delphi 7 Delphi 8 Delphi 2005 Delphi 2006 Delphi 2007 Delphi 2009 Delphi 2010 1988 march 2007 august 2008 august 2009 march 2, 1995 APL96 august, 1999 may 1, 2001 august 6, 2002 november 2003 november 2004 october 30, 2005 Python 3.0a2 Python 3.1 APL APL 2 Python 3.0 Python 3.0.1 Python 3.2 1960 august 1984 1996 december 7, 2007 february 13, 2009 june 27, 2009 february 20, 2011 B ABC december 3, 2008 1981 1987 Python Python 1.5.2 Python 1.6 Python 2.0 Python 2.1 Python 2.2 Python 2.2.1 Python 2.2.2 Python 2.3a2 Python 2.2.3 Python 2.3 Python 2.3.1 Python 2.3.2 Python 2.3.3 Python 2.3.4 Python 2.4 Python 2.4.1 Python 2.4.2 Python 2.5 Python 2.5.1 Python 2.6 Python 2.6.1 Python 2.6.2 Python 2.6.3 Python 2.7 Python 2.7.1 1991 april 13, 1999 april 17, 2001 april 10, 2002 october 14, 2002 july 29, 2003 september 23, 2003 october 3, 2003 december 19, 2003 may 27, 2004 november 30, 2004 march 30, 2005 september 19, 2006 april 19, 2007 october 1, 2008 december 4, 2008 april 14, 2009 october 2, 2009 july 4, 2010 november 27, 2010 Object Pascal Borland september 5, 2000 october 16, 2000 december 21, 2001 february 19, 2003 may 30, 2003 september 28, 2005 1985 Turbo Pascal B-O Flow-Matic COBOL COBOL 61 COBOL 61 COBOL COBOL 68 ANS COBOL 74 ANSI COBOL 85 ISO/ANSI OO COBOL COBOL 2002 ISO/ANSI 1957 1958 1959 1961 Extended 1965 1968 1974 1985 1997 december 2002 1962 Rex 1.00 Rex 2.00 Rex 3.00 Rexx 3.20 ANSI Rexx Object Rexx may 1979 1980 1982 1984 february 25, 1997 Pascal Pascal AFNOR 1970 1983 Oberon Oberon-2 Active Oberon 1987 1991 2001 PL/M Modula 2 Modula-2 ISO Modula-2 ISO Modula Generic Extension 1972 1975 1979 june 1, 1996 Ada Ada 83 ANSI Ada ISO Ada 95 december 19, 1998 Ada 2006 (draft) Ada 2005 january 1983 1987 1995 2005 PL/I PL/1 ANS 1979 NetRexx NetRexx 1.150 C# C# C# 2.0 march 9, 2007 1991 C# (ECMA) (beta) C# 2.0 1964 1976 july 23, 1999 june 26, 2000 (ISO) november 2005 Concurrent C december 13, 2001 march 28, 2003 july 2003 1984 ISO C C# 3.0 CPL BCPL B C (K&R) ANSI C ISO C ISO C (C99) C# 3.5 C Classic C (C89) (C90) (C95) (beta) C# 3.0 C# 4.0 1963 july 1967 1969 1971 1978 december 1, 1999 november 6, 2006 november 19, 2007 april 12, 2010 1989 december 15, 1990 april 1, 1996 JScript JScript september 2005 JOVIAL JOVIAL I JOVIAL II JOVIAL 3 Objective-C may 1996 Objective-C 2.0 Objective-C 2.1 1959 august 28, 2009 1960 1961 1965 1983 JavaScript 2.0 JavaScript 2.0 august 7, 2006 Java 6 update 7 Cmm LiveScript JavaScript Java 2 (v6.0 beta) Java 6 Java 6 update 2 Java 6 update 11 Java 6 update 14 Java 6 update 24 1995 JavaScript 1.5 (draft 1) (draft 4) december 2004 july 5, 2007 july 11, 2008 december 2, 2008 june 10, 2009 CORAL 64 CORAL 66 1992 december 1995 C++03 ISO/IEC december 11, 2006 february 15, 2011 C with Classes C++ ARM C++ C++98 ANSI/ISO february 18, 1999 april 26, 2002 C++0x draft C++1x draft 1964 1966 april 1980 1989 1998 2003 2008 CLU july 1983 ECMAScript ECMAScript ed3 ECMAScript ed4 (draft) july 22, 2009 2002 Java 2 (v1.5.0) Simula 67 1974 june 1997 december 1999 Java 2 (v1.4) Java 2 Java 2 (v1.4.1_03) Java 2 (v5.0) (beta 2) Java 2 (v5.0) Java 2 (v5.0 update 3) Java 2 (v5.0 update 8) Java 2 (v5.0 update 12) Java 2 (v5.0 update 16) Java 2 (v5.0 update 17) Java 2 (v5.0 update 18) Java 2 (v5.0 update 21) Simula I Oak Java 1 Java 2 (v1.2) Java 2 (v1.3) Java 2 (v1.4.0_01) Java 2 (v1.4.1) (v1.4.1_02) (beta 1) july 11, 2008 1964 1967 may 8, 2000 early access june 11, 2003 june 28, 2004 september 30, 2004 april 28, 2005 august 11, 2006 may 31, 2007 december 2, 2008 march 24, 2009 september 11, 2009 Mesa june 1991 may 23, 1995 december 8, 1998 june 4, 2002 september 2002 february 27, 2003 Java 2 (v1.4.2) Java 2 (v1.4.2_01) Java 2 (v1.4.2_02) february 5, 2004 Java 2 (v1.4.2_18) ALGOL W february 6, 2002 Java 2 (v1.4.2_03) Java 2 (v1.4.2_04) Java 2 (v1.4.2_05) Java 2 (v1.4.2_06) Java 2 (v1.4.2_19) 1977 Ruby april 29, 2003 august 26, 2003 october 22, 2003 december 13, 2003 july 11, 2008 december 2, 2008 Ruby 1.9.2 preview 1 IAL ALGOL 58 ALGOL 60 1966 ALGOL 68 Cedar Ruby 0.95 Ruby 1.1 alpha 0 Ruby 1.3.2 Ruby 1.6.7 Ruby 1.6.8 march 8, 2004 june 30, 2004 november 23, 2004 Ruby 1.8.2 Ruby 1.8.3 Ruby 1.8.5 Ruby 1.8.6 Ruby 1.8.7 Ruby 1.9.1 Ruby 1.9.2 february 24, 1993 august 13, 1997 Ruby 1.6.1 Ruby 1.6.5 Ruby 1.8 Ruby 1.8.1 Ruby 1.8.4 july 18, 2009 1958 1958 1960 december 1983 december 1995 april 2, 1999 september 27, 2000 september 19, 2001 march 1, 2002 december 24, 2002 december 25, 2004 september 21, 2005 december 24, 2005 august 25, 2006 march 13, 2007 may 31, 2008 january 30, 2009 august 18, 2010 1968 august 4, 2003 december 25, 2003 GOGOL GOGOL III Smalltalk Smalltalk-72 Smalltalk-74 Smalltalk-76 Smalltalk-78 Smalltalk-80 ANSI Smalltalk 1964 1967 1971 1972 1974 1976 1978 1980 may 19, 1998 sed Self 4.0 Self 4.1 Self 4.1.6 Self 4.2.1 Self 4.3 Self april 3, 2004 Sail 1973 Mainsail Eiffel Eiffel 2 Eiffel 3 july 10, 1995 Eiffel 4 Eiffel 4.2 ISE Eiffel 5 august 7, 2001 september 2002 ECMA Eiffel june 30, 2006 1968 1975 1986 1988 1993 december 11, 1996 february 6, 1998 2001 june 2005 ISWIM awk nawk PHP/FI PHP 2.0 PHP 3.0 PHP 4.0 PHP 4.1.0 PHP 4.2.0 PHP 4.2.2 PHP 4.2.3 PHP 4.3.0 PHP 4.3.1 PHP 4.3.2 PHP 4.3.3 PHP 4.3.4 PHP 4.3.5 PHP 4.3.6 PHP 4.3.7 PHP 4.3.8 PHP 4.3.10 PHP 4.4.1 PHP 4.4.2 PHP 4.4.4 PHP 4.4.7 PHP 4.4.8 PHP 4.4.9 1966 1978 1985 1995 nov. 13, 1997 june 6, 1998 may 22, 2000 december 8, 2001 april 22, 2002 july 22, 2002 september 6, 2002 december 27, 2002 feb. 17, 2003 may 29, 2003 august 25, 2003 november 3, 2003 march 26, april 15, june 3, july 13, 2004 december 15, 2004 october 31, 2005 january 13, 2006 august 17, 2006 may 3, 2007 january 3, 2008 august 7, 2008 KRC Sather 0.1 Sather 1.0 Sather 1.1 Sather 1.2.1 2004 2004 2004 1981 june 1991 mid-1994 september 1995 november 4, 1999 PHP 5.0.0 PHP 5.0.3 PHP 5.3.5 csh PHP 5.0.4 PHP 5.0.5 PHP 5.1.0 PHP 5.1.6 PHP 5.2.0 PHP 5.2.3 PHP 5.2.4 PHP 5.2.5 PHP 5.2.6 PHP 5.2.7 PHP 5.2.8 PHP 5.2.9 PHP 5.3 july 13, 2004 december 15, 2004 september 6, 2005 august 24, 2006 january 6, 2011 october 1978 Perl 5.005_50 april 3, 2005 november 24, 2005 november 2, 2006 may 31, 2007 august 30, 2007 november 9, 2007 may 1, 2008 december 4, 2008 december 8, 2008 february 26, 2009 june 30, 2009 SASL Perl 1.000 Perl 2.000 Perl 3.000 Perl 4.000 Perl 5.000 Perl 5.6.0 Perl 5.7,0 Perl 5.8.0 Perl 5.8.1 Perl 5.8.2 Perl 5.8.3 Perl 5.8.4 Perl 5.8.5 Perl 5.8.6 Perl 5.8.7 Perl 5.8.8 Perl 5.10 Perl 5.11.0 Perl 5.12.0 1976 july 26, 1998 Perl 5.12.3 Miranda december 18, 1987 january 5, 1988 october 18, 1989 march 21, 1991 october 18, 1994 march 28, 2000 september 2, 2000 july 18, 2002 september 26, 2003 november 5, 2003 january 1, 2004 april 23, 2004 july 21, 2004 november 30, 2004 june 3, 2005 february 2, 2006 december 18, 2007 october 2, 2009 april 12, 2010 january 21, 2011 1982 Objective Caml O’Caml 2 O’Caml 3.00 O’Caml 3.02 O’Caml 3.03 O’Caml 3.04 O’Caml 3.05 O’Caml 3.06 O’Caml 3.08.0 O’Caml 3.08.2 O’Caml 3.09.2 O’Caml 3.10.0 O’Caml 3.10.2 O’Caml 3.11.0 O’Caml 3.11.1 O’Caml 3.12.0 sh 1996 O’Caml 1.0.7 O’Caml 3.07 1969 december 11, 1997 1998 june 2000 july 30, 2001 dec 10, 2001 dec 12, 2001 july 29, 2002 august 20, 2002 september 29, 2003 july 13, 2004 november 2004 april 14, 2006 may 16, 2007 february 29, 2008 december 4, 2008 june 12, 2009 august 2, 2010 MS Basic 2.0 BASICA GW-Basic QuickBasic 1.0 QuickBasic 4.5 MS Basic PDS 7.0 MS PDS 7.1 Visual Basic 3.0 Visual Basic 4.0 Visual Basic 5.0 Visual Basic 6.0 VB.NET BASIC 1989 Visual Basic 1.0 Visual Basic 2.0 may 1, 1964 july 1975 1981 1983 1985 1988 1990 may 20, 1991 march 1992 june 93 september 1995 april 1997 june 16, 1998 (Visual Basic 7.0) Clos 2001 Lisp Lisp 1 Lisp 1.5 Common Lisp 1989 Common Lisp ANSI 1958 1959 1962 1984 december 8, 1994 6 6 Scheme Scheme MIT Scheme 84 Scheme IEEE Scheme R5RS Scheme R RS (draft) Scheme R RS 1990 1998 september 14, 2006 august 28, 2007 1975 1978 1984 Haskell 1.3 Haskell 1.4 Haskell 98 Haskell 2010 Haskell HP 2010.2.0.0 Haskell 1.0 Haskell 1.1 Haskell 1.2 Haskell 98 (announced) 1987 april 1, 1990 march 1992 may 1996 april 1997 february 1999 (revised) july 2010 ML SML SML ‘90 SML ‘97 december 2002 november 2009 1973 1984 1990 1997 SL5 Icon Unicon Languages SNOBOL SNOBOL 2 SNOBOL 3 SNOBOL 4 1976 1977 Caml 2-6.1 2001 february 27, 2011 Caml Caml 3.1 1962 april 1964 1965 1967 1987 1991 1993 10 © Éric Lévénez 1999-2011
PostScript level 3 PostScript level 3 PostScript PostScript level 2 PostScript level 3 v 3016 v 3017 1982 1992 september 11, 1996 OO Forth 2003 september 11, 2005 1987 Forth FIG-Forth Forth-83 ANS Forth ISO Forth 1968 1978 1983 1986 1997
Logo Object Logo Tcl Tcl/Tk Tcl/Tk 8.1 Tcl/Tk 8.2.3 Tcl/Tk 8.3 Tcl/Tk 8.4 Tcl/Tk 8.4.1 Tcl/Tk 8.4.2 Tcl/Tk 8.4.3 Tcl/Tk 8.4.4 Tcl/Tk 8.4.5 Tcl/Tk 8.4.6 Tcl/Tk 8.4.7 Tcl/Tk 8.4.8 Tcl/Tk 8.4.9 Tcl/Tk 8.4.11 Tcl/Tk 8.4.12 Tcl/Tk 8.4.13 Tcl/Tk 8.4.14 Tcl/Tk 8.4.15 Tcl/Tk 8.5 Tcl/Tk 8.5.5 Tcl/Tk 8.5.6 Tcl/Tk 8.5.7 Tcl/Tk 8.5.9 1968 1986 mid 1988 end 1988 april 1999 dec. 16, 1999 october 22, 2001 september 10, 2002 october 22, 2002 march 3, 2003 may 20, 2003 july 22, 2003 november 24, 2003 march 1, 2004 july 25, 2004 nov. 22, 2004 december 7, 2004 june 28, 2005 december 6, 2005 april 19, 2006 october 19, 2006 may 25, 2007 december 20, 2007 october 15, 2008 january 2009 april 15, 2009 september 8, 2010 FORTRAN IV Fortran 2000 FORTRAN I FORTRAN II FORTRAN III FORTRAN IV FORTRAN V Fortran 90 ISO Fortran 2003 Fortran 2008 FORTRAN (Fortran 66 ANS) (Fortran 77 ANSI) Fortran 95 ISO (draft) november 1954 october 1956 1957 end-1958 1962 1991 december 15, 1997 november 30, 2004 september 2010 1966 april 1978 A A+ september 30, 2002 Prolog Prolog II Prolog III 1988 1992 Prolog IV 1970 october 1982 1984 1997 J K Sharp APL 1990 1996 JOSS TELCOMP MUMPS MUMPS (ANSI) MUMPS (FIPS) MUMPS ISO M M ANSI Open M M ISO M ISO 1964 1965 1966 september 15, 1977 1986 1992 1994 dec 8, 1995 dec 11, 1995 1999 january 6, 2005 Modula 3 Delphi Delphi 5 Delphi 6 Delphi 7 Delphi 8 Delphi 2005 Delphi 2006 Delphi 2007 Delphi 2009 Delphi 2010 1988 march 2007 august 2008 august 2009 march 2, 1995 APL96 august, 1999 may 1, 2001 august 6, 2002 november 2003 november 2004 october 30, 2005 Python 3.0a2 Python 3.1 APL APL 2 Python 3.0 Python 3.0.1 Python 3.2 1960 august 1984 1996 december 7, 2007 february 13, 2009 june 27, 2009 february 20, 2011 B ABC december 3, 2008 1981 1987 Python Python 1.5.2 Python 1.6 Python 2.0 Python 2.1 Python 2.2 Python 2.2.1 Python 2.2.2 Python 2.3a2 Python 2.2.3 Python 2.3 Python 2.3.1 Python 2.3.2 Python 2.3.3 Python 2.3.4 Python 2.4 Python 2.4.1 Python 2.4.2 Python 2.5 Python 2.5.1 Python 2.6 Python 2.6.1 Python 2.6.2 Python 2.6.3 Python 2.7 Python 2.7.1 1991 april 13, 1999 april 17, 2001 april 10, 2002 october 14, 2002 july 29, 2003 september 23, 2003 october 3, 2003 december 19, 2003 may 27, 2004 november 30, 2004 march 30, 2005 september 19, 2006 april 19, 2007 october 1, 2008 december 4, 2008 april 14, 2009 october 2, 2009 july 4, 2010 november 27, 2010 Object Pascal Borland september 5, 2000 october 16, 2000 december 21, 2001 february 19, 2003 may 30, 2003 september 28, 2005 1985 Turbo Pascal B-O Flow-Matic COBOL COBOL 61 COBOL 61 COBOL COBOL 68 ANS COBOL 74 ANSI COBOL 85 ISO/ANSI OO COBOL COBOL 2002 ISO/ANSI 1957 1958 1959 1961 Extended 1965 1968 1974 1985 1997 december 2002 1962 Rex 1.00 Rex 2.00 Rex 3.00 Rexx 3.20 ANSI Rexx Object Rexx may 1979 1980 1982 1984 february 25, 1997 Pascal Pascal AFNOR 1970 1983 Oberon Oberon-2 Active Oberon 1987 1991 Modula-2 ISO 2001 PL/M Modula Modula 2 C++ Modula-2 ISO Generic Extension 1972 1975 1979 june 1, 1996 Ada Ada 83 ANSI Ada ISO Ada 95 december 19, 1998 Ada 2006 (draft) Ada 2005 january 1983 1995 2005 Simula 67 1979 1987 NetRexx C# C# 2.0 march 9, 2007 PL/I PL/1 ANS NetRexx 1.150 C# 1991 C# (ECMA) (beta) C# 2.0 1964 1976 july 23, 1999 june 26, 2000 (ISO) november 2005 Concurrent C december 13, 2001 march 28, 2003 july 2003 1983 1984 ISO C C# 3.0 CPL BCPL B C (K&R) ANSI C ISO C ISO C (C99) C# 3.5 C Classic C (C89) (C90) (C95) (beta) C# 3.0 C# 4.0 1963 july 1967 1969 1971 1978 december 1, 1999 november 6, 2006 november 19, 2007 april 12, 2010 1967 1989 december 15, 1990 april 1, 1996 JScript JScript september 2005 JOVIAL JOVIAL I JOVIAL II JOVIAL 3 Objective-C may 1996 Objective-C 2.0 Objective-C 2.1 1959 august 28, 2009 1960 1961 1965 1983 JavaScript 2.0 JavaScript 2.0 august 7, 2006 Java 6 update 7 Cmm LiveScript JavaScript Java 2 (v6.0 beta) Java 6 Java 6 update 2 Java 6 update 11 Java 6 update 14 Java 6 update 24 1995 JavaScript 1.5 (draft 1) (draft 4) december 2004 july 5, 2007 july 11, 2008 december 2, 2008 june 10, 2009 CORAL 64 CORAL 66 1992 december 1995 C++03 ISO/IEC december 11, 2006 february 15, 2011 C with Classes C++ ARM C++ C++98 ANSI/ISO february 18, 1999 april 26, 2002 C++0x draft C++1x draft 1964 1966 april 1980 1989 1998 2003 2008 CLU july 1983 ECMAScript ECMAScript ed3 ECMAScript ed4 (draft) july 22, 2009 2002 Java 2 (v1.5.0) Simula 67 1974 june 1997 december 1999 Java 2 (v1.4) Java 2 Java 2 (v1.4.1_03) Java 2 (v5.0) (beta 2) Java 2 (v5.0) Java 2 (v5.0 update 3) Java 2 (v5.0 update 8) Java 2 (v5.0 update 12) Java 2 (v5.0 update 16) Java 2 (v5.0 update 17) Java 2 (v5.0 update 18) Java 2 (v5.0 update 21) Simula I Oak Java 1 Java 2 (v1.2) Java 2 (v1.3) Java 2 (v1.4.0_01) Java 2 (v1.4.1) (v1.4.1_02) (beta 1) july 11, 2008 1964 1967 may 8, 2000 early access june 11, 2003 june 28, 2004 september 30, 2004 april 28, 2005 august 11, 2006 may 31, 2007 december 2, 2008 march 24, 2009 september 11, 2009 Mesa june 1991 may 23, 1995 december 8, 1998 june 4, 2002 september 2002 february 27, 2003 Java 2 (v1.4.2) Java 2 (v1.4.2_01) Java 2 (v1.4.2_02) february 5, 2004 Java 2 (v1.4.2_18) ALGOL W february 6, 2002 Java 2 (v1.4.2_03) Java 2 (v1.4.2_04) Java 2 (v1.4.2_05) Java 2 (v1.4.2_06) Java 2 (v1.4.2_19) 1977 Ruby april 29, 2003 august 26, 2003 october 22, 2003 december 13, 2003 july 11, 2008 december 2, 2008 Ruby 1.9.2 preview 1 IAL ALGOL 58 ALGOL 60 1966 ALGOL 68 Cedar Ruby 0.95 Ruby 1.1 alpha 0 Ruby 1.3.2 Ruby 1.6.7 Ruby 1.6.8 march 8, 2004 june 30, 2004 november 23, 2004 Ruby 1.8.2 Ruby 1.8.3 Ruby 1.8.5 Ruby 1.8.6 Ruby 1.8.7 Ruby 1.9.1 Ruby 1.9.2 february 24, 1993 august 13, 1997 Ruby 1.6.1 Ruby 1.6.5 Ruby 1.8 Ruby 1.8.1 Ruby 1.8.4 july 18, 2009 1958 1958 1960 december 1983 december 1995 april 2, 1999 september 27, 2000 september 19, 2001 march 1, 2002 december 24, 2002 december 25, 2004 september 21, 2005 december 24, 2005 august 25, 2006 march 13, 2007 may 31, 2008 january 30, 2009 august 18, 2010 1968 august 4, 2003 december 25, 2003 GOGOL GOGOL III Smalltalk Smalltalk-72 Smalltalk-74 Smalltalk-76 Smalltalk-78 Smalltalk-80 ANSI Smalltalk 1964 1967 1971 1972 1974 1976 1978 1980 may 19, 1998 sed Self 4.0 Self 4.1 Self 4.1.6 Self 4.2.1 Self 4.3 Self april 3, 2004 Sail 1973 Mainsail Eiffel Eiffel 2 Eiffel 3 july 10, 1995 Eiffel 4 Eiffel 4.2 ISE Eiffel 5 august 7, 2001 september 2002 ECMA Eiffel june 30, 2006 1968 1975 1986 1988 1993 december 11, 1996 february 6, 1998 2001 june 2005 ISWIM awk nawk PHP/FI PHP 2.0 PHP 3.0 PHP 4.0 PHP 4.1.0 PHP 4.2.0 PHP 4.2.2 PHP 4.2.3 PHP 4.3.0 PHP 4.3.1 PHP 4.3.2 PHP 4.3.3 PHP 4.3.4 PHP 4.3.5 PHP 4.3.6 PHP 4.3.7 PHP 4.3.8 PHP 4.3.10 PHP 4.4.1 PHP 4.4.2 PHP 4.4.4 PHP 4.4.7 PHP 4.4.8 PHP 4.4.9 1966 1978 1985 1995 nov. 13, 1997 june 6, 1998 may 22, 2000 december 8, 2001 april 22, 2002 july 22, 2002 september 6, 2002 december 27, 2002 feb. 17, 2003 may 29, 2003 august 25, 2003 november 3, 2003 march 26, april 15, june 3, july 13, 2004 december 15, 2004 october 31, 2005 january 13, 2006 august 17, 2006 may 3, 2007 january 3, 2008 august 7, 2008 KRC Sather 0.1 Sather 1.0 Sather 1.1 Sather 1.2.1 2004 2004 2004 1981 june 1991 mid-1994 september 1995 november 4, 1999 PHP 5.0.0 PHP 5.3.5 csh PHP 5.0.3 PHP 5.0.4 PHP 5.0.5 PHP 5.1.0 PHP 5.1.6 PHP 5.2.0 PHP 5.2.3 PHP 5.2.4 PHP 5.2.5 PHP 5.2.6 PHP 5.2.7 PHP 5.2.8 PHP 5.3 july 13, 2004 december 15, 2004 PHP 5.2.9 january 6, 2011 october 1978 april 3, 2005 september 6, 2005 november 24, 2005 august 24, 2006 november 2, 2006 may 31, 2007 august 30, 2007 november 9, 2007 may 1, 2008 december 4, 2008 december 8, 2008 february 26, 2009 june 30, 2009 SASL Perl 2.000 Perl 3.000 Perl 4.000 Perl 5.000 Perl 5.005_50 Perl 5.6.0 Perl 5.7,0 Perl 5.8.0 Perl 5.8.1 Perl 5.8.2 Perl 5.8.3 Perl 5.8.4 Perl 5.8.5 Perl 5.8.8 Perl 5.11.0 Smalltalk Perl 1.000 july 26, 1998 Perl 5.8.6 Perl 5.8.7 Perl 5.10 Perl 5.12.0 Perl 5.12.3 1976 Miranda december 18, 1987 january 5, 1988 october 18, 1989 march 21, 1991 october 18, 1994 march 28, 2000 september 2, 2000 july 18, 2002 september 26, 2003 november 5, 2003 january 1, 2004 april 23, 2004 july 21, 2004 november 30, 2004 june 3, 2005 february 2, 2006 december 18, 2007 october 2, 2009 april 12, 2010 january 21, 2011 1982 Objective Caml O’Caml 2 O’Caml 3.00 O’Caml 3.02 O’Caml 3.03 O’Caml 3.04 O’Caml 3.05 O’Caml 3.06 O’Caml 3.08.0 O’Caml 3.08.2 O’Caml 3.09.2 O’Caml 3.10.0 O’Caml 3.10.2 O’Caml 3.11.0 O’Caml 3.11.1 O’Caml 3.12.0 sh 1996 O’Caml 1.0.7 O’Caml 3.07 1969 december 11, 1997 1998 june 2000 july 30, 2001 dec 10, 2001 dec 12, 2001 july 29, 2002 august 20, 2002 september 29, 2003 july 13, 2004 november 2004 april 14, 2006 may 16, 2007 february 29, 2008 december 4, 2008 june 12, 2009 august 2, 2010 MS Basic PDS 7.0 BASIC 1971 MS Basic 2.0 BASICA GW-Basic QuickBasic 1.0 QuickBasic 4.5 MS PDS 7.1 Visual Basic 1.0 Visual Basic 2.0 Visual Basic 3.0 Visual Basic 4.0 Visual Basic 5.0 Visual Basic 6.0 VB.NET 1989 may 1, 1964 july 1975 1981 1983 1985 1988 1990 may 20, 1991 march 1992 june 93 september 1995 april 1997 june 16, 1998 (Visual Basic 7.0) Clos 2001 Lisp Lisp 1 Lisp 1.5 Common Lisp 1989 Common Lisp ANSI 1958 1959 1962 1984 december 8, 1994 6 6 Scheme Scheme MIT Scheme 84 Scheme IEEE Scheme R5RS Scheme R RS (draft) Scheme R RS 1990 1998 september 14, 2006 august 28, 2007 1975 1978 1984 Haskell 1.3 Haskell 1.4 Haskell 98 Haskell 2010 Haskell HP 2010.2.0.0 Haskell 1.0 Haskell 1.1 Haskell 1.2 Haskell 98 (announced) 1987 april 1, 1990 march 1992 may 1996 april 1997 february 1999 (revised) july 2010 ML SML SML ‘90 SML ‘97 december 2002 november 2009 1973 1984 1990 1997 SL5 Icon Unicon Languages SNOBOL SNOBOL 2 SNOBOL 3 SNOBOL 4 1976 1977 Caml 2-6.1 2001 february 27, 2011 Caml Caml 3.1 1962 april 1964 1965 1967 1987 1991 1993 © Éric Lévénez 1999-2011
mainstream technology practical offshoot
12 OO makes code understandable by encapsulating moving parts. FP makes code understandable by minimizing moving parts.
Michael Feathers, author of “Working with Legacy Code”
13 number classification
14 perfect # ∑(f(#)) - # = #
(sum of the factors of a #) - # = # (sum of the factors of a #) = 2#
6: 1 + 2 + 3 + 6 = 12 (2x6) 28: 1 + 2 + 4 + 7 + 14 + 28 = 56 (2x28) 496: . . .
15 classification
∑(f(#)) = 2# perfect ∑(f(#)) > 2# abundant ∑(f(#)) < 2# deficient
16 imperative
17 imperative classifier
18 19 20 8
2
21 22 23 internal state cohesive composed
testable
refactorable
24 (slightly more) functional
25 26 (slightly) more functional classifier
27 28 29 30 no internal state
less need for scoping refactorable testable
31 “functional” is more a way of thinking than a tool set
32 pure 1st class/ functions higher order functions concepts
strict evaluation recursion
33 1st1st classclass/ / higher-orderhigher-order purepure functionsfunctions functionsfunctions
concepts strict evaluation evaluation recursion
34 higher-order functions
35 higher-order functions functions that can either take other functions as arguments or return them as results
36 extracting reusable code:
— extract via Template Method DP — encapsulate verb via Command DP
37 38 39 same “unit of work” code
40 41 What’s so special about... closures
42 minimal code to demonstrate closures
43 44 closest Java equivalent to closure code
45 46 let the language manage state
47 languages handle memory allocation garbage collection time concurrency state tests specification-based testing frameworks
48 1st-class functions
49 1st-class functions functions can appear anywhere other language constructs can appear
50 51 52 NumberClassifier using Functional Java
53 54 55 fold
1 2 3 4 5 6 7 8 9 10 11 12
56 think about results, not steps
57 12
1 2 3 4 5 6 7 8 9 10 11 12
58 think about results, not steps
59 academia alert!
60 currying
given:
then: currying transforms a multi-argument function so that it can be called as a chain of single-argument functions
61 partial application
partial application fixes a number of arguments to a function, producing another function of smaller arity
62 currying & partial application
63 return a version that always multiplies by 4
==
64 65 currying vs partial application
partial application
66 currying vs partial application
partial application
currying
67 function reuse
new, different tools
68 currying (& recursion)
69 currying
70 pure functions
71 pure functions
no memory or i/o side effects
72 purity if the result isn’t used, it can be removed a particular invocation with a set of parameters returns a constant value enables memoization execution order can change parallel execution
73 recursion
74 iteration & recursion
75 iterate a list
76 list perspective
1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 8 9 10
77 recurse a list
78 iterative & recursive filtering
79 iterative filtering
80 recursive filtering
81 functional vs imperative
who’s minding the state?
82 recursive filtering
think about results, not steps http://www.scala-lang.org/node/135 83 think about results, not steps what about things you want to control?
performance?
new, different tools
84 imperative number classifier optimized!
85 optimized functional classifier
86 optimized factors
think about results, not steps special thanks to Michal Karwanski for optimizations to my optimizations 87 post-imperative
Google challenged college grads to write code for 100 CPU computers...... they failed http://broadcast.oreilly.com/2008/11/warning-x-x-1-may-be-hazardous.html ingrained imperativity learn MapReduce http://code.google.com/edu/submissions/mapreduce-minilecture/listing.html sound familiar?
88 languages handle garbage collection concurrency state time tests iteration
. . .
89 strict evaluation
90 academia alert!
91 strict all elements pre-evaluated evaluation divByZero
=4 non-strict elements evaluated evaluation as needed
92 laziness
93 Lazy List
94 laziness
95 Lazy list in
96 laziness
97 nomenclature
foldLeft() inject()
filter() findAll()
98 Tersest NumberClassifier
99 perfect #’s
100 ∞ perfect # sequence
101 ∞ sequence
new, different tools 102 concurrency
103 http://www.infoq.com/presentations/Simple-Made-Easy
104 variables assume 1 thread of control, 1 timeline not atomic non-composable subtle visibility rules with concurrency: lock & pray
105 life w/ variables
variable ? ???
variable ???
106 identity
explicit semantic
identity value value
identity value
state
107 identity, state, & time term meaning immutable data in a value persistent data structure series of causally related identity values over time state identity at a point in time relative: before/ time simultaneous/after ordering of causal values
108 time model Process events (pure functions)
F F F
v1 v2 v3 v4
States Identity (immutable values) (succession of states)
Observers/perception/memory
109 ‘s Software Transactional Memory
v1 v2 v3 v4
v1 v2 v3 v4
v1 v2 v3 v4
v1 v2 v3 v4
F F F F transactions F F F F F
F F F
110 actors
111 PerfectNumber
112 new, different tools
113 thinking functionally
114 immutability over state transitions
http://www.ibm.com/developerworks/java/library/j-jtp02183/index.html
115 immutable … simple to construct & test automaticallyautomatically threadthread safesafe do not need a copy constructor does not need an implementation of clone make good Map keys & Set elements nono needneed forfor defensivedefensive copyingcopying hashas “failure“failure atomicity”atomicity”
116 immutable ! ensure the class cannot be overridden make fields final all state set in constructor no mutating methods defensively copy mutable object fields
117 let the language manage state as much as possible
118 119 @Immutable properties have private, final backing fields updates result in ReadOnlyPropertyException map & tuple style constructors generated default equals, hashCode, toString methods defensive copies of mutable references Arrays & cloneables use clone() collections wrapped in immutable wrappers updates result in UnsupportedOperationException
120 results over steps
121 composition over structure
122 structural reuse
123 functional reuse
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12 fold
1 2 3 4 5 6 7 8 9 101 11 12 filter
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 1 11 12 map
124 functional reuse
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8 9 10 11 12 fold
1 2 3 4 5 6 7 8 9 101 11 12 filter
map
125 composition
126 declarative over imperative
127 paradigm over tool
128 summary
129 functional thinking new ways of thinking cede control to languages & runtimes immediately beneficial beginning steps following the general trend in language design enables entirely new capabilities
130 for more info
http://ibm.co/nf-ft
131 ?’s please fill out the session evaluations
director / software architect NEAL FORD meme wrangler
® ThoughtWorks
[email protected] This work is licensed under the Creative Commons 2002 Summit Boulevard, Atlanta, GA 30319 Attribution-Share Alike 3.0 License. nealford.com thoughtworks.com memeagora.blogspot.com http://creativecommons.org/licenses/by-sa/3.0/us/ @neal4d
132