PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/presentation/sheeple-talk-22-10-09.org

http://github.com/sykopomp/sheeple
Org | 282 lines | 273 code | 9 blank | 0 comment | 5 complexity | 10aca92437e97b7535434321dbeb41ce MD5 | raw file
  1. #+LaTeX_CLASS: beamer
  2. #+MACRO: BEAMERMODE presentation
  3. #+TITLE: Sheeple: Dynamic Object-Orientation for CL
  4. #+AUTHOR: Kat Marchán
  5. * What is Class-orientation?
  6. ** Setting up the strawman...
  7. #+LaTeX:\pause
  8. *** Write general blueprints, create objects based on them to hold some (limited) changeable state.
  9. #+LaTeX:\pause
  10. *** Otherwise, objects are fairly static
  11. #+LaTeX:\pause
  12. *** Nothing object-oriented about classes.
  13. Saying class-orientation is "object-oriented" is a damn filthy lie.
  14. #+LaTeX:\pause
  15. *** "Static constructs considered harmful" (for dynamic languages)
  16. ** Hope?
  17. #+LaTeX:\pause
  18. *** Python - arbitrary attributes
  19. #+LaTeX:\pause
  20. *** Ruby - open classes
  21. #+LaTeX:\pause
  22. *** Smalltalk - Everything is an instance of a class, including classes.
  23. #+LaTeX:\pause
  24. *** CLOS - class redefinition, change-class, EQL specializers, MOP
  25. ** Example: Developing a game
  26. Goal: Write a game
  27. You're mapping to conceptual objects. Class-orientation seems like a perfect fit.
  28. #+LaTeX:\pause
  29. Or is it?
  30. ** Example: The class hierarchy
  31. Let's write a class hierarchy!
  32. #+LaTeX:\pause
  33. #+LaTeX:\begin{verbatim}
  34. Class GameObject (no instances)
  35. \_ Class Weapon (no instances)
  36. \_ Class Sword (no instances)
  37. \_ Class FireSword (maybe an instance?)
  38. \_ ??? (What now?)
  39. #+LaTeX:\end{verbatim}
  40. #+LaTeX:\pause
  41. #+LaTeX:\begin{center}
  42. #+LaTeX:\includegraphics[height=2cm]{/home/zkat/hackery/lisp/sheeple/presentation/jizzinmypants.jpg}
  43. Suggestions?
  44. #+LaTeX:\end{center}
  45. ** Example: Working toward a solution
  46. Some solutions:
  47. *** Class explosion
  48. *** Programmatic class creation
  49. *** Data-driven programming
  50. ** Example: Solutions
  51. Class explosion:
  52. #+latex:\pause
  53. *** Still class-oriented.
  54. *** Lots of manual class writing
  55. *** Might make code... difficult
  56. #+LaTeX:\pause
  57. Do you really want to write FireIceMagicMissileGoldenGodForeverSwordOfDoom?
  58. ** Example: Solutions
  59. Programmatic class creation:
  60. #+latex:\pause
  61. *** May not actually be possible in your language
  62. *** Programmatic classes are sketchy, at best. Using them may be difficult and arcane.
  63. *** Reusability possibly out the window.
  64. ** Example: Solutions
  65. Data-driven programming
  66. #+latex:\pause
  67. *** Eject! Eject!
  68. Class-orientation can't actually do what you want, so you need to use something else
  69. *** Blessing
  70. You've escaped the hell that is class-based programming
  71. ** Example: Screw this.
  72. #+latex:\begin{block}{From a paper on Self}
  73. "How hardcore do you want to be?
  74. How many lifetimes do you want to waste?"
  75. #+latex:\end{block}
  76. * What is Object-oriented Programming?
  77. ** What is Object-Oriented Programming?
  78. #+latex:\begin{center}
  79. Object-oriented programming: A different paradigm for putting together your program.
  80. #+latex:\end{center}
  81. ** Overview of objects
  82. #+LaTeX:\pause
  83. *** Objects are like other objects, and share each others' behavior.
  84. #+LaTeX:\pause
  85. *** No separate entity to confuse the process.
  86. #+LaTeX:\pause
  87. *** Delegate behavior *and* data.
  88. ** Structuring an application with objects
  89. #+LaTeX:\pause
  90. *** Create an object
  91. #+LaTeX:\pause
  92. *** Copy or delegate to that object
  93. #+LaTeX:\pause
  94. *** New object can act as a prototype for other objects
  95. #+LaTeX:\pause
  96. *** Don't Panic!
  97. Lots of other "object-oriented" design principles you learned still apply, in a good way.
  98. ** Example: Game objects revisited
  99. Back to the game. Now with objects:
  100. #+LaTeX:\pause
  101. #+LaTeX:\begin{verbatim}
  102. Object
  103. \_ Object, add some Weapon-like attributes
  104. \_ Weapon, add some Sword-like attributes
  105. \_ Sword, add some Fire-like attributes
  106. \_ ???, add some ???-like attributes
  107. #+LaTeX:\end{verbatim}
  108. #+LaTeX:\pause
  109. #+latex:\begin{center}
  110. #+LaTeX:\includegraphics[height=2cm]{/home/zkat/hackery/lisp/sheeple/presentation/Awesome_Face_bigger.png}
  111. Awesome!
  112. #+latex:\end{center}
  113. ** Example: That's totally not different at all! D:<
  114. What's the difference?
  115. *** Make objects different by making them different
  116. *** Incremental development on a live system
  117. *** Objects defined by what they do, and what attributes they have, not by an abstract blueprint
  118. ** Example (cont'd)
  119. What does this mean?
  120. *** Create a new object that implements the new behavior. Delegate what you want.
  121. #+LaTeX:\pause
  122. *** Programmatic creation of objects is easy and natural (not like there's any other way to do it!)
  123. #+LaTeX:\pause
  124. *** Heck, make programmatic object creation part of the design tool
  125. #+LaTeX:\pause
  126. #+latex:\begin{center}
  127. #+LaTeX:\includegraphics[height=3.5cm]{/home/zkat/hackery/lisp/sheeple/presentation/caveman.jpg}
  128. #+latex:\end{center}
  129. ** Object-orientation in the wild
  130. *** Prototype and Properties "patterns" (for classes)
  131. *** JavaScript
  132. *** MUDs
  133. **** LambdaMOO
  134. **** LPC
  135. **** DGD
  136. * CLOS
  137. ** CLOS
  138. *** Common Lisp Object System. Integrates with Common Lisp
  139. *** Multiple inheritance
  140. *** Multiple dispatch
  141. *** Method combination
  142. *** Metaobject Protocol
  143. ** More dynamic than other class-based systems
  144. #+LaTeX:\pause
  145. *** Redefinition of classes with instance updates
  146. (Very complicated, though. See CLHS 4.3.6)
  147. #+LaTeX:\pause
  148. *** Adding/removing generic functions and methods.
  149. **** Does not require redefinition of a class.
  150. **** Generic functions and classes conceptually separate.
  151. **** Very dynamic
  152. #+LaTeX:\pause
  153. *** Instances can change classes
  154. (Again, pretty tricky. CLHS 7.2)
  155. ** WANT
  156. I want:
  157. #+latex:\pause
  158. *** something with CLOS' nice features, but object-oriented
  159. #+latex:\pause
  160. *** something portable, built on Common Lisp
  161. #+latex:\pause
  162. *** an API similar to CLOS.
  163. #+latex:\pause
  164. *** A pony.
  165. * Sheeple
  166. ** Sheeple
  167. #+LateX:\begin{center}
  168. #+LaTeX:\pause
  169. #+LaTeX:\includegraphics[height=5cm]{/home/zkat/hackery/lisp/sheeple/doc/logo.png}
  170. Sheeple: Dynamic Object-Orientation for Common Lisp.
  171. #+LaTeX:\end{center}
  172. ** Influences
  173. *** Written by Kat Marchán and Adlai Chandrasekhar
  174. *** Influenced by:
  175. **** CLOS
  176. **** Slate: http://slatelanguage.org
  177. **** Self: http://research.sun.com/self
  178. **** Io: http://iolanguage.com
  179. **** LambdaMOO and similar MUD systems
  180. ** Objects, with delicious CLOS
  181. *** Lisp is dynamic. The object system should dynamic.
  182. #+LaTeX:\pause
  183. *** CLOS+Object-orientation. What more could you possibly want?
  184. #+LaTeX:\pause
  185. #+BEGIN_SRC lisp
  186. (object :parents *pony*) => Here's your pony.
  187. #+END_SRC
  188. ** Looks suspiciouly like CLOS on the surface
  189. *** Multiple inheritance
  190. *** Multiple dispatch
  191. *** Method combination
  192. *** Lisp integration (autoboxing)
  193. *** Interface looks like a M-% of CLOS' API
  194. ** But has all the proto-goodies you might want underneath...
  195. *** Objects define behavior
  196. *** Completely dynamic
  197. *** Dynamic delegation of data (not just behavior)
  198. ** ...and it still performs well
  199. Self showed that prototype languages can be efficient.
  200. *** Self-inspired maps ("hidden classes")
  201. *** Fast property access, reuse of known techniques from Class-land
  202. *** Delegation can lead to smaller memory footprint
  203. NewtonScript exploited this for an embedded system.
  204. ** It's fun.
  205. Being able to manipulate application on the fly makes programming more fun and productive!
  206. #+LaTeX:\pause
  207. #+latex:\begin{center}
  208. #+LaTeX:\includegraphics[height=4.5cm]{/home/zkat/hackery/lisp/sheeple/presentation/calvin-trex.jpg}
  209. This T-Rex just downloaded Sheeple.
  210. #+latex:\end{center}
  211. ** Object API
  212. Object creation
  213. #+LaTeX:\pause
  214. *** Make a new object
  215. #+LaTeX:\begin{verbatim}
  216. (object)
  217. #+LaTeX:\end{verbatim}
  218. #+LaTeX:\pause
  219. *** Make a new object, that delegates to another object
  220. #+LaTeX:\begin{verbatim}
  221. (object :parents *foo*)
  222. #+LaTeX:\end{verbatim}
  223. #+LaTeX:\pause
  224. *** Copy an existing object, directly inheriting its properties locally
  225. #+LaTeX:\begin{verbatim}
  226. (clone *foo*)
  227. #+LaTeX:\end{verbatim}
  228. ** Property API
  229. Creating and managing properties
  230. #+LaTeX:\pause
  231. *** Add a property
  232. #+LaTeX:\begin{verbatim}
  233. (add-property *foo* 'name "value")
  234. #+LaTeX:\end{verbatim}
  235. #+LaTeX:\pause
  236. *** Access a property
  237. #+LaTeX:\begin{verbatim}
  238. (property-value *foo* 'name)
  239. #+LaTeX:\end{verbatim}
  240. #+LaTeX:\pause
  241. *** Access a delegated property from an object's descendant
  242. #+LaTeX:\begin{verbatim}
  243. (property-value (object :parents *foo*) 'name)
  244. #+LaTeX:\end{verbatim}
  245. #+LaTeX:\pause
  246. *** Remove the property
  247. #+LaTeX:\begin{verbatim}
  248. (remove-property *foo* 'name)
  249. #+LaTeX:\end{verbatim}
  250. ** Message API
  251. Creating messages, replies, and dispatching them
  252. #+LaTeX:\pause
  253. *** Create a message (think generic functions)
  254. #+LaTeX:\begin{verbatim}
  255. (defmessage synergize (a b)
  256. (:documentation "Synergizes A and B"))
  257. #+LaTeX:\end{verbatim}
  258. #+LaTeX:\pause
  259. *** Create a reply (think methods)
  260. #+LaTeX:\begin{verbatim}
  261. (defreply synergize ((a =string=) (b =string=))
  262. (concatenate 'string a b))
  263. #+LaTeX:\end{verbatim}
  264. #+LaTeX:\pause
  265. *** Call a message (think uhh... calling a function :D)
  266. #+LaTeX:\begin{verbatim}
  267. (synergize "foo" "bar") => "foobar"
  268. #+LaTeX:\end{verbatim}
  269. ** Links:
  270. *** Project page on my site:
  271. http://sykosomatic.org/sheeple
  272. *** Project page on Github:
  273. http://github.com/zkat/sheeple