Naïveté vs. Experience How We Thought We Could Use Scala and Clojure, and How We Actually Did
Who
 
<ul><li>AI, Distributed Simulation, Code Generation, Machine Vision
C, C++, Java, CLIPS, Clojure, Scala
Co-author of  The Joy of Clojure   </li><ul><li>http://joyofclojure.com </li></ul><li>Local Boy </li></ul>Michael Fogus: P...
Why
Java
Compression Potential
Compression Potential
Essential Boilerplate
Essential Boilerplate equals hashCode get set public Foo toString
Essential Boilerplate equals hashCode get set public Foo toString try catch finally ; { } @override static int System.out ...
What
<ul>Java </ul>
<ul>Java </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>
<ul>Java </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>List<Map<String,String>> foo = new Ar...
<ul>Java </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>Да
Java != JVM
Reprieve
<ul><li>JRuby
Jython
Jess
Scala
Clojure
Groovy
Rhino </li></ul>
<ul><li>JRuby
Jython
Jess
Scala
Clojure
Groovy
Rhino </li></ul><ul><li>Scala
Clojure </li></ul>
<ul>Scala </ul>
<ul>Scala </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>
<ul>Scala </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>val foo = List[Map[String,String]]()...
<ul>Scala </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>Да
<ul>Clojure </ul>
<ul>Clojure </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>
<ul>Clojure </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>(def foo {}) (assoc foo “bar” “baz”)
<ul>Clojure </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>zzz
<ul>Clojure </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul><ul><ul><li>Runtime </li></ul></ul...
Essential Boilerplate public class  Person { private  String lastName; private  String firstName; private  Person spouse; ...
(spouse !=  null  ?  &quot; married to &quot;  + spouse.getFirstName() +  &quot;.&quot;  :  &quot;.&quot; );  }  </li></ul...
Less Boilerplate <ul><li>case class   Person ( val  firstName : String ,  val  lastName: String ,  val  spouse: Option [ P...
(spouse !=  null  ?  &quot; married to &quot;  + spouse.getFirstName() +  &quot;.&quot;  :  &quot;.&quot; );  }  </li></ul...
Kittens <ul><li>case class   Person ( val  firstName : String ,  val  lastName: String ,  val  spouse: Option [ Person ]) ...
(spouse !=  null  ?  &quot; married to &quot;  + spouse.getFirstName() +  &quot;.&quot;  :  &quot;.&quot; );  }  </li></ul...
Kittens and Aquaman <ul><li>case class   Person ( val  firstName : String ,  val  lastName: String ,  val  spouse: Option ...
(spouse !=  null  ?  &quot; married to &quot;  + spouse.getFirstName() +  &quot;.&quot;  :  &quot;.&quot; );  }  </li></ul...
Scala <ul><li>case class   Person ( val  firstName : String ,  val  lastName: String ,  val  spouse: Option [ Person ]) {
override def  toString(): String  = firstName +  &quot; &quot;  + lastName +
(spouse  match  {
case  None  =>  &quot;.&quot;
case  Some(s) =>  &quot; married to &quot;  + s.firstName +  &quot;.&quot;
});
} </li></ul>By  default , Scala classes are immutable.
 
Disingenuous
Of Course... <ul>( defrecord   Person  [fname lname spouse] <li>Object
( toString  [_]
( str  fname  &quot; &quot;  lname
( when-let  [n ( :fname  spouse)]
( str   &quot; married to &quot;  n))
.))) </li></ul>By  default , Scala classes are immutable.
 
<ul>Scala Won (mostly) </ul>
<ul>How </ul>
<ul><li>Embedded XML
Everything is an Object
Functional Programming
List Comprehensions
Case Classes
Pattern Matching
Interoperability
Currying
Implicits </li></ul>
Architecture
services The Internet
services The Internet
services The Internet
services The Internet
services The Internet
services The Internet
services The Internet
Upcoming SlideShare
Loading in...5
×

Naïveté vs. Experience

7,370

Published on

Presentation given at the 2010 Commercial Users of Functional Programming conference.

Published in: Technology
1 Comment
1 Like
Statistics
Notes
  • http://0845.com/Inr

    I tide fashion

    Good-looking, not expensive

    Free transport
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
7,370
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
57
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Naïveté vs. Experience

  1. 1. Naïveté vs. Experience How We Thought We Could Use Scala and Clojure, and How We Actually Did
  2. 2. Who
  3. 4. <ul><li>AI, Distributed Simulation, Code Generation, Machine Vision
  4. 5. C, C++, Java, CLIPS, Clojure, Scala
  5. 6. Co-author of The Joy of Clojure </li><ul><li>http://joyofclojure.com </li></ul><li>Local Boy </li></ul>Michael Fogus: Programmer
  6. 7. Why
  7. 8. Java
  8. 9. Compression Potential
  9. 10. Compression Potential
  10. 11. Essential Boilerplate
  11. 12. Essential Boilerplate equals hashCode get set public Foo toString
  12. 13. Essential Boilerplate equals hashCode get set public Foo toString try catch finally ; { } @override static int System.out boolean . void import String Exception throws toString toString throws throws finally finally finally get get equals hashCode try } System.out boolean toString throws throws finally get public Foo catch finally ; int import String Exception throws toString get equals get toString try finally static import String toString throws finally equals try toString throws get finally String Exception hashCode finally { @override int void Exception toString throws finally hashCode toString throws finally public Foo finally int Exception @override static finally hashCode try throws throws static @override hashCode throws hashCode @override void toString toString int hashCode void finally finally public Foo int hashCode @override void toString toString int hashCode void finally finally public Foo int hashCode @override void toString toString int hashCode void finally finally public Foo int toString static finally equals try finally String toString throws finally toString finally
  13. 14. What
  14. 15. <ul>Java </ul>
  15. 16. <ul>Java </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>
  16. 17. <ul>Java </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>List<Map<String,String>> foo = new ArrayList<HashMap<String,String>>(); foo.add(new HashMap() {{ put(“bar”, “baz”); }});
  17. 18. <ul>Java </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>Да
  18. 19. Java != JVM
  19. 20. Reprieve
  20. 21. <ul><li>JRuby
  21. 22. Jython
  22. 23. Jess
  23. 24. Scala
  24. 25. Clojure
  25. 26. Groovy
  26. 27. Rhino </li></ul>
  27. 28. <ul><li>JRuby
  28. 29. Jython
  29. 30. Jess
  30. 31. Scala
  31. 32. Clojure
  32. 33. Groovy
  33. 34. Rhino </li></ul><ul><li>Scala
  34. 35. Clojure </li></ul>
  35. 36. <ul>Scala </ul>
  36. 37. <ul>Scala </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>
  37. 38. <ul>Scala </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>val foo = List[Map[String,String]]() foo ++ Map(&quot;bar&quot; -> &quot;baz&quot;)
  38. 39. <ul>Scala </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>Да
  39. 40. <ul>Clojure </ul>
  40. 41. <ul>Clojure </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>
  41. 42. <ul>Clojure </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>(def foo {}) (assoc foo “bar” “baz”)
  42. 43. <ul>Clojure </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul>zzz
  43. 44. <ul>Clojure </ul><ul><ul><li>Compiler </li></ul></ul><ul><ul><li>Problem </li></ul></ul><ul><ul><li>Runtime </li></ul></ul>Да
  44. 45. Essential Boilerplate public class Person { private String lastName; private String firstName; private Person spouse; public Person(String firstName, String lastName, Person spouse) { this .lastName = lastName; this .firstName = firstName; this .spouse = spouse; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public Person getSpouse() { return spouse; } public String toString() { <ul><li>return firstName + &quot; &quot; + lastName +
  45. 46. (spouse != null ? &quot; married to &quot; + spouse.getFirstName() + &quot;.&quot; : &quot;.&quot; ); } </li></ul>}
  46. 47. Less Boilerplate <ul><li>case class Person ( val firstName : String , val lastName: String , val spouse: Option [ Person ]) { </li></ul>public Person(String firstName, String lastName, Person spouse) { this .lastName = lastName; this .firstName = firstName; this .spouse = spouse; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public Person getSpouse() { return spouse; } public String toString() { <ul><li>return firstName + &quot; &quot; + lastName +
  47. 48. (spouse != null ? &quot; married to &quot; + spouse.getFirstName() + &quot;.&quot; : &quot;.&quot; ); } </li></ul>}
  48. 49. Kittens <ul><li>case class Person ( val firstName : String , val lastName: String , val spouse: Option [ Person ]) { </li></ul>public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public Person getSpouse() { return spouse; } public String toString() { <ul><li>return firstName + &quot; &quot; + lastName +
  49. 50. (spouse != null ? &quot; married to &quot; + spouse.getFirstName() + &quot;.&quot; : &quot;.&quot; ); } </li></ul>}
  50. 51. Kittens and Aquaman <ul><li>case class Person ( val firstName : String , val lastName: String , val spouse: Option [ Person ]) { </li></ul><ul><li>override def toString(): String = firstName + &quot; &quot; + lastName + </li></ul><ul><li>return firstName + &quot; &quot; + lastName +
  51. 52. (spouse != null ? &quot; married to &quot; + spouse.getFirstName() + &quot;.&quot; : &quot;.&quot; ); } </li></ul>}
  52. 53. Scala <ul><li>case class Person ( val firstName : String , val lastName: String , val spouse: Option [ Person ]) {
  53. 54. override def toString(): String = firstName + &quot; &quot; + lastName +
  54. 55. (spouse match {
  55. 56. case None => &quot;.&quot;
  56. 57. case Some(s) => &quot; married to &quot; + s.firstName + &quot;.&quot;
  57. 58. });
  58. 59. } </li></ul>By default , Scala classes are immutable.
  59. 61. Disingenuous
  60. 62. Of Course... <ul>( defrecord Person [fname lname spouse] <li>Object
  61. 63. ( toString [_]
  62. 64. ( str fname &quot; &quot; lname
  63. 65. ( when-let [n ( :fname spouse)]
  64. 66. ( str &quot; married to &quot; n))
  65. 67. .))) </li></ul>By default , Scala classes are immutable.
  66. 69. <ul>Scala Won (mostly) </ul>
  67. 70. <ul>How </ul>
  68. 71. <ul><li>Embedded XML
  69. 72. Everything is an Object
  70. 73. Functional Programming
  71. 74. List Comprehensions
  72. 75. Case Classes
  73. 76. Pattern Matching
  74. 77. Interoperability
  75. 78. Currying
  76. 79. Implicits </li></ul>
  77. 80. Architecture
  78. 81. services The Internet
  79. 82. services The Internet
  80. 83. services The Internet
  81. 84. services The Internet
  82. 85. services The Internet
  83. 86. services The Internet
  84. 87. services The Internet
  85. 88. services The Internet
  86. 89. The Internet
  87. 90. The Internet
  88. 91. The Internet
  89. 92. The Internet
  90. 93. Naïveté
  91. 94. <ul><li>Embedded XML
  92. 95. Everything is an Object
  93. 96. Functional Programming
  94. 97. List Comprehensions
  95. 98. Case Classes
  96. 99. Pattern Matching
  97. 100. Interoperability
  98. 101. Currying
  99. 102. Implicits </li></ul>
  100. 103. <ul><li>Interoperability
  101. 104. Everything is an Object </li></ul><ul><li>Embedded XML </li></ul><ul><li>Functional Programming
  102. 105. List Comprehensions
  103. 106. Case Classes
  104. 107. Pattern Matching
  105. 108. Currying
  106. 109. Implicits </li></ul>
  107. 110. <ul><li>Interoperability </li></ul><ul><li>Functional Programming
  108. 111. List Comprehensions
  109. 112. Pattern Matching
  110. 113. Currying </li></ul>
  111. 114. Experience
  112. 115. <ul><li>Interoperability
  113. 116. Type Aliases </li></ul><ul><li>Traits </li></ul><ul><li>Functional Programming
  114. 117. List Comprehensions </li></ul><ul><li>Immutability </li></ul><ul><li>Pattern Matching
  115. 118. Currying </li></ul><ul><li>Closures </li></ul>
  116. 119. Disingenuous
  117. 120. Dis ingenuous
  118. 121. <ul>Interoperability (near seamless – essential) </ul>
  119. 122. <ul>Type Aliases </ul>
  120. 123. <ul>D.I. </ul>
  121. 124. Type Aliases <ul><li>class Service extends IService {
  122. 125. def get(ref:ReferenceParam):ComponentReturn = { ... }
  123. 126. ...
  124. 127. } </li></ul>By default , Scala classes are immutable.
  125. 128. Type Aliases <ul><li>class Service extends IService {
  126. 129. def get(ref: ReferenceParam ): ComponentReturn = { ... }
  127. 130. ...
  128. 131. } </li></ul>
  129. 132. Type Aliases <ul><li>class Service extends IService {
  130. 133. def get(ref: ReferenceParam ): ComponentReturn = { ... }
  131. 134. ...
  132. 135. } </li></ul><ul><li>type ReferenceParam = java.util.Map[String,String] </li></ul><ul><li>type ComponentReturn = java.util.Map[String,Object] </li></ul>
  133. 136. <ul>Traits </ul>
  134. 137. <ul>D.I. </ul>
  135. 138. <ul>D.I. </ul>
  136. 139. Traits <ul><li>class Service extends IService {
  137. 140. def get(ref: ReferenceParam ): ComponentReturn = { ... }
  138. 141. ...
  139. 142. } </li></ul><ul><li>trait RPCTypes { </li></ul><ul><li>type ReferenceParam = java.util.Map[String,String] </li></ul><ul><li>type ComponentReturn = java.util.Map[String,Object]
  140. 143. } </li></ul>
  141. 144. Traits <ul><li>class Service extends IService with RPCTypes {
  142. 145. def get(ref: ReferenceParam ): ComponentReturn = { ... }
  143. 146. ...
  144. 147. } </li></ul><ul><li>trait RPCTypes { </li></ul><ul><li>type ReferenceParam = java.util.Map[String,String] </li></ul><ul><li>type ComponentReturn = java.util.Map[String,Object]
  145. 148. } </li></ul>
  146. 149. RPCTypes LocalTypes CachedTypes DelayedTypes ... RPCTypes LocalTypes ... The Internet
  147. 150. <ul>Functional Programming </ul>
  148. 151. <ul>List Comprehensions </ul>
  149. 152. <ul>Immutability </ul>
  150. 153. When a tree falls in a lonely forest ... does it make a sound? – Charles Riborg Mann and George Ransom Twiss
  151. 154. If a pure function mutates some local data in order to produce an immutable return value, is that ok? – Rich Hickey
  152. 155. <ul>Pattern Matching (a language for error shapes) </ul>
  153. 156. <ul>Currying (gratuitous, but cool, control structures) </ul>
  154. 157. <ul>Closures (gratuitous, but cool, simplified delays) </ul>
  155. 158. <ul>Woe </ul>
  156. 159. <ul><li>Breaking Changes
  157. 160. Optional Immutability
  158. 161. Weak Laziness
  159. 162. Less Functional
  160. 163. Grand Hierarchies
  161. 164. Literals-lite </li></ul>
  162. 165. <ul><li>Breaking Changes
  163. 166. Optional Immutability
  164. 167. Weak Laziness
  165. 168. Less Functional
  166. 169. Grand Hierarchies </li></ul><ul><li>Literals-lite </li></ul>Clojure!
  167. 170. Thanks To <ul><li>You
  168. 171. My employer
  169. 172. Dean Wampler for feedback
  170. 173. Rich Hickey and Martin Odersky for Clojure and Scala
  171. 174. Chris Houser my co-author
  172. 175. Ryan Tomayko for the screaming face
  173. 176. The fam </li></ul>
  174. 177. Questions? (example questions below) <ul><li>Joel or Mike?
  175. 178. Is Scala too complicated?
  176. 179. Best zombie movies?
  177. 180. Kobaia is de hundin?
  178. 181. Favorite hangout in Baltimore?
  179. 182. What's with the tie? </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×