Your SlideShare is downloading. ×
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Clojure oo-quickie
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Clojure oo-quickie

269

Published on

Lightning talk on object orientation in Clojure from Jfokus 2012.

Lightning talk on object orientation in Clojure from Jfokus 2012.

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
269
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Vad clojure lärt migom objektorientering (som jag inte lärt mig av Java)
  • 2. Jag Ville Svärd{ :twitter @villesv :email ville.svard@agical.com :lojalitet Agical :skador [ Clojure, TDD ]}
  • 3. Nyfikenhet
  • 4. "Id leave out classes" - James Gosling(åtminstone om man får tro Allen Holub)
  • 5. (clojure)(Beware, here be parens)
  • 6. Clojure metodanrop Javaobject.method(arg) Clojure(method object arg)
  • 7. Hello World(defn hello-world [] (println "Hello" "world"))(hello-world)=> Hello world nil
  • 8. Inkapsling Skydda Abstrahera
  • 9. Inkapsling (Java)public class Capsule { private int seeds; public int getSeeds() { return seeds; } public void setSeeds(int seeds) { this.seeds = seeds; }}
  • 10. Inkapsling (Java)Capsule c = new Capsule();c.setSeeds(42);c.getSeeds();
  • 11. Inkapsling (Clojure){:seeds 0};; or(defrecord Capsule [seeds])
  • 12. Inkapsling (Clojure)(def c {:seeds 0});; or(def c (Capsule. 0));; regardless(:seeds c)=> 0
  • 13. Inkapsling (Clojure) Inga setters!
  • 14. Inkapsling (Clojure)Accessor är en funktion
  • 15. Abstraktion! Inkapslar associativt beteende(map :seeds [(Capsule. 14) (Capsule. 38)])=> (14 38)
  • 16. PolymorfismLägga till beteende till data
  • 17. Expression problem "...add new cases to the datatype and new functions over the datatype, ..." --Philip Wadler, 1998
  • 18. Expression problemObjektorientering gör det lätt att lägga till nya datastrukturer .size .add .get .clear SVÅRT! ArrayList LinkedList Existerande implementation Stack Ny (data)typ
  • 19. Expression problemFunktionell programmering gör det lätt att lägga till nya funktioner count conj nth empty Ny funktion list vector Existerande implementation map SVÅRT!
  • 20. I clojure?Protocols!
  • 21. Definiera...;; New function(ality)(defprotocol Ordered (ordered? [this]))
  • 22. ...och lös problemet!;; Implement for existing type;; (without touching it!)(extend-type java.util.ArrayList Ordered (ordered? [this] true));; or, even better,(extend-type java.util.List Ordered (ordered? [this] true))(ordered? (java.util.ArrayList.))=> true
  • 23. ...och lös problemet!;; New type(deftype Bucket [...] ;; Implements existing functionality Ordered (ordered? [this] false) ... )
  • 24. OO goes to eleven
  • 25. Separation of concerns
  • 26. Räds ej
  • 27. Inga klasser ellerhierarkier skadadesunder förberedandet av detta tal
  • 28. Lärdomar Arv är ingen förutsättningKlass är ingen förutsättning
  • 29. "Id leave out classes" För den diskussionsvillige:{ :twitter @villesv :email ville.svard@agical.com}
  • 30. AttributionsStuart Sierra, "Solving theexpression problem withClojure 1.2"Rich Hickey, "ClojureProtocols"WikipediaDebasish Gosh, Random ThoughtsOn Clojure Protocols

×