Not Everything Is An Object
-
Upload
gary-short -
Category
Technology
-
view
2.174 -
download
0
description
Transcript of Not Everything Is An Object
![Page 1: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/1.jpg)
Not Everything is an Object
By @garyshort
![Page 2: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/2.jpg)
Agenda
• The road to here• Where we are now• What OOD/P is good for• What it’s not good for• The solution• Demo• Questions.
![Page 3: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/3.jpg)
The Road to Here
http://www.flickr.com/photos/fyngyrz/
![Page 4: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/4.jpg)
Where we are Now
http://www.flickr.com/photos/gtarded/
![Page 5: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/5.jpg)
What OOP/D is Good For
http://www.flickr.com/photos/gserafini/
![Page 6: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/6.jpg)
What is it Not Good For?
http://www.flickr.com/photos/aloshbennett/
![Page 7: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/7.jpg)
The Solution
![Page 8: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/8.jpg)
What Does it Mean to be Functional?
• First order functions• Function like constructs• Stateless• Immutable data.
![Page 9: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/9.jpg)
Clojure
• A Lisp• Dynamic• Functional– Impure
• “Lockless” Concurrency• Macros
• JVM• Java Interop• Fast• Persistent collections• Easy to learn.
![Page 10: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/10.jpg)
Introduction to Clojure
• Java.Lang.Object• Arbitrary sized numbers• Ratios: 18/20• Nil is null and is treated as false.
![Page 11: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/11.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 12: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/12.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 13: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/13.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 14: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/14.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 15: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/15.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 16: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/16.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 17: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/17.jpg)
Tail Recursion
http://www.flickr.com/photos/43911015@N05
![Page 18: Not Everything Is An Object](https://reader035.fdocuments.us/reader035/viewer/2022062418/555a23fad8b42ab3088b48a2/html5/thumbnails/18.jpg)
I’m Bored... Show me the Code!
http://www.flickr.com/photos/peter_hasselbom/