Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Not Everything Is An Object

A presentations highlighting the weaknesses in OO programming and showing how functional languages, in this case Clojure, could be the answer.

  • Login to see the comments

  • Be the first to like this

Not Everything Is An Object

  1. 1. Not Everything is an Object<br />By @garyshort<br />
  2. 2. Agenda<br />The road to here<br />Where we are now<br />What OOD/P is good for<br />What it’s not good for<br />The solution<br />Demo<br />Questions.<br />
  3. 3. The Road to Here<br /><br />
  4. 4. Where we are Now<br /><br />
  5. 5. What OOP/D is Good For<br /><br />
  6. 6. What is it Not Good For?<br /><br />
  7. 7. The Solution<br />
  8. 8. What Does it Mean to be Functional?<br />First order functions<br />Function like constructs<br />Stateless<br />Immutable data.<br />
  9. 9. Clojure<br />A Lisp<br />Dynamic<br />Functional<br />Impure<br />“Lockless” Concurrency<br />Macros<br /><ul><li>JVM
  10. 10. Java Interop
  11. 11. Fast
  12. 12. Persistent collections
  13. 13. Easy to learn.</li></li></ul><li>Introduction to Clojure<br />Java.Lang.Object<br />Arbitrary sized numbers<br />Ratios: 18/20<br />Nil is null and is treated as false.<br />
  14. 14. Persistent Collections<br />Immutable<br />Cheap to copy<br />Examples<br />(1 2 3)<br />List – sequential lookup time<br />[1 2 3]<br />Vector – logarithmic lookup time<br />{“key” 1, 3 7, “foo” “bar”}<br />Hashmap – unordered, key value pairs.<br />
  15. 15. Equality Vs Identity<br />Equality<br />Two objects are equal<br />Two cylinders maybe equal if their volumes are equal<br />Identity<br />Two pointers to the same object<br />Clojure favours equality :-O.<br />
  16. 16. Clojure is Impure so has Mutability<br />Var<br />Mutable pointer to immutable data<br />You can’t change the data<br />But you can change what data the var points to<br />But vars hold global data, function defs etc .<br />This data won’t change<br />So why are vars mutable?<br />So we can patch running software. <br />
  17. 17. The Reader<br />Other programming languages<br />Compiler<br />Text -&gt; lexing and parsing -&gt; AST<br />Clojure<br />The Reader<br />Text -&gt; lexing and parsing -&gt; Literals (Data)<br />As soon as it reads a complete literal it’s passed to...<br />
  18. 18. The Evaluator<br />Compile Phase<br />Traverses the data<br />Symbol evaluation<br />Symbols evaluate into Vars<br />Symbol Dog evaluates to a var in the current namespace<br />Symbol MyPets/Dog evaluates to var in namespace MyPets<br />List evaluation<br />Lists evaluate into function calls<br />(+ 1 2 3)<br />Process macros<br />Execute phase<br />Effects the special forms<br />Calls functions.<br />
  19. 19. Special Forms<br />Reserved symbol<br />Denotes special list evaluation<br />Not a function call – it’s “something else”<br />Def, if, do, let, quote, var, fn, loop, recur, throw, try, ., new, set!<br />If a list starts with any of those it’s evaluated in a special way particular to that form<br />(if condition a b?)<br />(if (been_drinking) (hungover) (happy))<br />(if (have_beers) (drink))<br />
  20. 20. Tail Recursion<br /><br />
  21. 21. I’m Bored... Show me the Code!<br /><br />
  22. 22. Questions?<br /><br /><br />@garyshort<br />