Not Everything is an Object - Rocksolid Tour 2013
-
Upload
gary-short -
Category
Documents
-
view
276 -
download
1
Transcript of Not Everything is an Object - Rocksolid Tour 2013
![Page 1: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/1.jpg)
Not Everything is an Object
By Gary ShortGibraltar Software
![Page 2: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/2.jpg)
What this Session is not…
• OO hating• Deep dive of Clojure• If you’ve written a Clojure App, you’ll probably
not learn anything.
![Page 3: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/3.jpg)
What this Session is…
• Point out why OO dev is hard sometimes• Show you that there is an alternative• “It shouldn’t be this hard”.
![Page 4: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/4.jpg)
4
Introduction
• Gary Short• Head of Gibraltar Labs– “Skunk Works” division of Gibraltar Software
• MVP C#– Python – NodeJS
• [email protected]• @garyshort• Facebook.com/theOtherGaryShort
![Page 5: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/5.jpg)
The Road to Here
http://www.flickr.com/photos/fyngyrz/
![Page 6: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/6.jpg)
Ada Lovelace
• 1842 - 1843 Lovelace translated a memoir of an Italian mathematician on Charles Baggage’s newest proposed machine... the Analytical Engine. The article she wrote contained the entire specification of how to calculate Bernoulli numbers with the Engine. This is believed to be the first ever computer program.
![Page 7: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/7.jpg)
The 1940s
• Then in the 1940’s along comes the first recognisable computers and we get programming languages to go with them...
• 1943 - Plankalkül (Konrad Zuse) • 1943 - Colossus• 1949 - C-10
![Page 8: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/8.jpg)
The 1950s
• In the 1950s the first three modern programming languages whose descendants are still in widespread use today were designed:
• FORTRAN (1955), the "FORmula TRANslator", invented by John Backus et al.;
• LISP, the "LISt Processor", invented by John McCarthy et al.;
• COBOL, the COmmon Business Oriented Language, created by the Short Range Committee, heavily influenced by Grace Hopper.
![Page 9: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/9.jpg)
More 1950s
• 1951 - Regional Assembly Language • 1952 - Autocode • 1954 - FORTRAN • 1954 - IPL (forerunner to LISP) • 1955 - FLOW-MATIC (forerunner to COBOL) • 1957 - COMTRAN (forerunner to COBOL) • 1958 - LISP • 1958 - ALGOL 58 • 1959 - FACT (forerunner to COBOL) • 1959 - COBOL
![Page 10: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/10.jpg)
The 1960s
• 1962 - APL • 1962 - Simula • 1964 - BASIC • 1964 - PL/I
![Page 11: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/11.jpg)
The 1970s
• 1970 - Pascal • 1970 - Forth • 1972 - C • 1972 - Smalltalk • 1972 - Prolog • 1973 - ML • 1975 - Scheme • 1978 - SQL
![Page 12: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/12.jpg)
The 1980s
• 1983 - Ada • 1983 - C++ • 1985 - Eiffel • 1986 - Erlang • 1987 - Perl • 1989 - FL
![Page 13: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/13.jpg)
The 1990s
• 1990 - Haskell • 1991 - Python • 1991 - Java • 1993 - Ruby • 1993 - Lua • 1994 - ANSI Common Lisp • 1995 - JavaScript • 1995 - PHP • 1997 - Rebol
![Page 14: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/14.jpg)
Where we are Now
http://www.flickr.com/photos/gtarded/
![Page 15: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/15.jpg)
What OOP/D is Good For
http://www.flickr.com/photos/gserafini/
![Page 16: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/16.jpg)
What is it Not Good For?
http://www.flickr.com/photos/aloshbennett/
![Page 17: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/17.jpg)
Also, we really suck at OOM…
![Page 18: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/18.jpg)
Also hierarchies are brittle…
![Page 19: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/19.jpg)
Also, OOPs get complex real fast…
![Page 20: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/20.jpg)
The Solution
![Page 21: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/21.jpg)
What Does it Mean to be Functional?
• First order functions• Function like constructs• Stateless• Immutable data
![Page 22: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/22.jpg)
Clojure
• A Lisp• Dynamic• Functional– Impure
• “Lockless” Concurrency• Macros
• JVM• Java Interop• Fast• Persistent collections• Easy to learn.
![Page 23: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/23.jpg)
Introduction to Clojure
• Java.Lang.Object• Arbitrary sized numbers• Ratios: 18/20• Nil is null and is treated as false
![Page 24: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/24.jpg)
Persistent Collections
• Immutable– Cheap to copy
• Examples– (1 2 3)• List – sequential lookup time
– [1 2 3]• Vector – logarithmic lookup time
– {“key” 1, 3 7, “foo” “bar”}• Hashmap – unordered, key value pairs
![Page 25: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/25.jpg)
Equality Vs Identity
• Equality– Two objects are equal• Two cylinders maybe equal if their volumes are equal
– Identity• Two pointers to the same object
– Clojure favours equality :-O
![Page 26: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/26.jpg)
Clojure is Impure so has Mutability
• Var– Mutable pointer to immutable data• You can’t change the data• But you can change what data the var points to
• But vars hold global data, function defs etc .• This data won’t change• So why are vars mutable?• So we can patch running software.
![Page 27: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/27.jpg)
The Reader
• Other programming languages– Compiler• Text -> lexing and parsing -> AST
• Clojure– The Reader• Text -> lexing and parsing -> Literals (Data)• As soon as it reads a complete literal it’s passed to...
![Page 28: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/28.jpg)
The Evaluator
• Compile Phase– Traverses the data
• Symbol evaluation– Symbols evaluate into Vars
» Symbol Dog evaluates to a var in the current namespace» Symbol MyPets/Dog evaluates to var in namespace MyPets
• List evaluation– Lists evaluate into function calls
» (+ 1 2 3)
• Process macros
– Execute phase• Effects the special forms• Calls functions.
![Page 29: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/29.jpg)
Special Forms
• Reserved symbol– Denotes special list evaluation
• Not a function call – it’s “something else”
• Def, if, do, let, quote, var, fn, loop, recur, throw, try, ., new, set!
• If a list starts with any of those it’s evaluated in a special way particular to that form
• (if condition a b?)• (if (been_drinking) (hungover) (happy))• (if (have_beers) (drink))
![Page 30: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/30.jpg)
Let’s Talk About the ‘crazy’ Syntax
(prn “Hello World!”)
![Page 31: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/31.jpg)
Maybe it’s not so Crazy
Console.WriteLine(“Hello World”)
![Page 32: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/32.jpg)
Looping
![Page 33: Not Everything is an Object - Rocksolid Tour 2013](https://reader035.fdocuments.in/reader035/viewer/2022062319/555a23f1d8b42ab3088b489c/html5/thumbnails/33.jpg)
Tail Recursion
http://www.flickr.com/photos/43911015@N05