Scala Presentation Work

3,393 views

Published on

Published in: Technology
1 Comment
3 Likes
Statistics
Notes
  • watch this presentation

    http://skillsmatter.com/podcast/java-jee/phil-miller-ease-into-scala-web-development/zx-489
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
3,393
On SlideShare
0
From Embeds
0
Number of Embeds
159
Actions
Shares
0
Downloads
0
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

Scala Presentation Work

  1. 1. Ease into Scala Web Development Phil Miller
  2. 2. Speaker Qualifications <ul><li>Google Wave webapp in Scala / Spring
  3. 3. 10 years in Java web dev </li></ul>
  4. 4. Ease into Scala Web Development <ul><li>Introduction to Scala
  5. 5. Decision Matrix
  6. 6. A Scala/Spring webapp recipe </li></ul>
  7. 7. Introduction to Scala <ul><li>JVM language, low barrier to entry
  8. 8. Created by Martin Odersky 2001
  9. 9. Static Typing with Type inference
  10. 10. Expressive, compact
  11. 11. Encourages functional style
  12. 12. Object-Orientated – everything an object, traits
  13. 13. Concurrency via Actors
  14. 14. IDE support and a REPL
  15. 15. Scala frameworks + a gazillion Java ones </li></ul>
  16. 16. Introduction to Scala Variable Value <ul><li>Static Typing with Type inference
  17. 17. Prove absence of some runtime errors
  18. 18. Removes fear of refactoring
  19. 19. Performance optimizations </li></ul>var foo: String ”bar” :String var foo 1 :Integer
  20. 20. def getAccounts(fn: Account => Boolean) = { val accounts = ... // gets a List[Account] accounts filter fn } Introduction to Scala <ul><li>Provides a List of Accounts, based on a Predicate Function
  21. 21. Encapsulation protects source of List[Account] </li></ul>
  22. 22. def getAccounts(fn: Account => Boolean) = { val accounts = ... // gets a List[Account] accounts filter fn } <ul><li>Static Typing with Type inference
  23. 23. Expressive and compact syntax
  24. 24. Encourages a functional style </li></ul>Introduction to Scala
  25. 25. def getAccounts(fn: Account => Boolean) = { val accounts = ... // gets a List[Account] accounts filter fn } <ul><li>Static Typing with Type inference
  26. 26. Expressive and compact syntax
  27. 27. Encourages a functional style </li></ul>Introduction to Scala
  28. 28. def getAccounts( fn: Account => Boolean ) = { val accounts = ... // gets a List[Account] accounts filter fn } <ul><li>Static Typing with Type inference
  29. 29. Expressive and compact syntax
  30. 30. Encourages a functional style </li></ul>Introduction to Scala
  31. 31. def getAccounts( fn: Account => Boolean ) = { val accounts = ... // gets a List[Account] accounts filter fn } <ul><li>Object-Orientated – everything an object , traits </li></ul>Introduction to Scala
  32. 32. val curried = (as: List[Account]) => (fn: Account => Boolean) => as filter fn <ul><li>Encourages a functional style
  33. 33. Expressiveness and comprehension indirectly proportional </li></ul>Introduction to Scala
  34. 34. Scala pain <ul><li>Type System intimidating
  35. 35. Implicit conversions & parameters
  36. 36. IDE support not equal to Java yet
  37. 37. Compile times
  38. 38. Java 3 rd party API interop – i.e. Hibernate @OneToMany
  39. 39. Readability
  40. 40. You won't want to write Java again </li></ul>
  41. 41. Reality check <ul>” ..Is there enough value choosing Scala over Java? You would have to determine that for yourself. It is a very challenging business case to switch languages. Are the benefits of switching from Java to Scala so great and so provable that it makes conclusive sense to switch? For some perhaps, but for most large enterprises that drive the JVM stack blueprint, not likely.” http://enfranchisedmind.com/blog/posts/what-killed-lisp-could-kill-haskell-as-well/#comment-37144 </ul>
  42. 42. Decision Matrix: Properties of a Language <ul><li>Writability: expressive , compactness
  43. 43. Readability: comprehension , maintainable
  44. 44. Tooling & IDEs
  45. 45. Testability
  46. 46. Performance
  47. 47. Portability
  48. 48. Frameworks
  49. 49. http://gist.github.com/325374 </li></ul>
  50. 50. Decision Matrix: Properties of a Language Java Scala Writability Readability IDE support
  51. 51. IOU Example webapp <ul><li>Spring 3.0
  52. 52. Maven
  53. 53. Junit
  54. 54. Specs
  55. 55. Scala
  56. 56. http://github.com/idrop/scala-spring </li></ul>Html / jQuery Spring 3.0 MVC Container MyController MyService Storage: Actor
  57. 57. Best path into Scala web dev <ul><li>Webapp using Scala, Spring, Maven
  58. 58. Same deployment unit as Java
  59. 59. Choose something ancillary to your big project
  60. 60. Don't give up over IDE support
  61. 61. Dojos with REPL </li></ul>
  62. 62. Java Spring Maven webapp => Scala <ul><li>Existin g passing suite of unit tests
  63. 63. Copy src/main/java & src/test/java to src/main/scala & src/test/scala
  64. 64. Rename copied java files to *.scala
  65. 65. Scala-ify pom.xml
  66. 66. Don't use an IDE yet!
  67. 67. Scala-ify src/main/scala first
  68. 68. New suite of Scala tests pass </li></ul>
  69. 69. Some alternatives to Scala / Spring <ul><li>Java 7
  70. 70. Lift
  71. 71. Akka
  72. 72. C# </li></ul>
  73. 73. References <ul><li>Decision Matrix: http://gist.github.com/325374
  74. 74. Scala-Spring: http://github.com/idrop/scala-spring
  75. 75. Simon Peyton-Jones on funtional programming: http://tinyurl.com/se-radio-haskell
  76. 76. Akka Tutorial: http://jonasboner.com/2010/01/04/introducing-akka.html
  77. 77. Play! http://www.playframework.org/documentation/1.1-trunk/scala
  78. 78. Lift: http://liftweb.net/
  79. 79. Scala for Java Refugees: http://www.codecommit.com/blog/scala/roundup-scala-for-java-refugees
  80. 80. Daily Scala: http://daily-scala.blogspot.com/
  81. 81. Coding Dojos: http://www.codingdojo.org/ </li></ul>
  82. 82. public List<Account> getActiveAccounts() { List<Account> accounts = ..... List<Account> list = new ArrayList<Account>(); for (Account account : accounts) { if (account.isActive()) list .add(account); } return list ; } Introduction to Scala <ul><li>Static Typing with Type inference
  83. 83. Expressive and compact syntax
  84. 84. Encourages a functional style </li></ul>
  85. 85. Evolving to a Functional Style
  86. 86. <ul>Scala Proficiency Warm-up </ul><ul><li>Level of Proficiency in Scala Questionnaire
  87. 87. Use Scala REPL to determine proportion of responses at each proficiency level </li></ul>Grpah here
  88. 88. Becoming 'functional' /** * all accounts for this user, given user id */ public List<Account> getAccounts(String id) { return accounts.get(id); } public List <Account> getAccounts(String id) { return Collections.unmodifiableList (accounts.get(id)); }
  89. 89. private Predicate<Account> active = new Predicate<Account>() { public boolean apply(Account a) { return a.isActive(); } } public List<Account> getAccounts( String id, Predicate<Account> filter ) { List<Account> accounts = getAccounts(id); Iterable<Account> filter =Iterables.filter(accounts, filter ); return Lists.newArrayList(filter); } <ul><li>Google Collections </li></ul>Becoming 'functional'
  90. 90. public void editAccounts(List<Account> accounts) { .......... } public Account editAccount(Account a) { .......... } <ul><li>Void methods – Simon Peyton-Jones </li></ul>Becoming 'functional'
  91. 91. <ul><li>Way off pure functional concepts like lazy evaluation, monads </li></ul>Becoming 'functional'
  92. 92. Why Scala from Java? <ul><li>Low barrier to entry
  93. 93. JVM
  94. 94. Type inference & Type safety
  95. 95. Expressive datastructures, pattern matching
  96. 96. Correctness in concurrency
  97. 97. REPL
  98. 98. Traits </li></ul>
  99. 99. Typing Dynamic Typing Static Typing Strong typing 1 . Groovy, Jruby, Javascript 2 . Java, Scala, C# Weak typing 3 . Perl C Variable Value var a: String ” 1” :String var a ” 1”
  100. 100. Scala v. others Scala Groovy Ruby Clojure C# Low barrier to entry from Java JVM Type inference Type safety Expressive Correctness in concurrency REPL Traits

×