[start] scala

Download [Start] Scala

Post on 10-May-2015

6.031 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • 1.println("Hello World!")

2. Do you knowObject-oriented Programming? 3. Do you know FunctionalProgramming? 4. Do you know Scala? 5. [Start] Scala!@mumoshu 6. # of atnders phpjava scala jspython perl0 51015 7. Categorize 8. PHP, Java, ScalaWeb dev General PurposeScalaPHP Java 9. PHP, Java, ScalaWeb dev General PurposeDynamically Statically typedtyped ScalaPHP Java 10. PHP, Java, ScalaWeb devGeneral Purpose Shorter codeDynamicallyStatically typedtypedScala Longer code PHP Java 11. Scala has NOTHING NEW! 12. PHP and Scala PHP + Static Typing + Shorter code= Scala ?! 13. Java and Scala Java + Shorter code= Scala ?! 14. Really short? 15. Basic computation Calculate the sum in imperative style 16. Basic computation Calculate the sum in imperative style1 + 2 + 3 = 6 17. Basic computation Calculate the sum in imperative style1 + 2 + 3 = 6sum = 0sum = sum + 1sum = sum + 2sum = sum + 3 18. MY Ranking1. (Ruby)2. Scala3. (JavaScript)4. PHP5. Java 19. Sum with Javaint[] array = new int[] { 1, 2, 3 };int sum = 0;for (int i=0; i sum += x}println(sum) 35. Scala + foreachvar array = Array(1, 2, 3)var sum = 0array foreach { x => sum += x}println(sum) 36. Scala + foreachvar array = Array(1, 2, 3)var sum = 0array foreach {sum += _}println(sum) 37. Sum with `reduce` Calculate the sum in functional styl 38. Sum with `reduce` Calculate the sum in functional stylesum = 1 + 2 + 3sum = 3 + 3sum = 6 39. Sum with `reduce` Calculate the sum in functional stylesum = 1 + 2 + 3 40. Sum with `reduce` Calculate the sum in functional style1. (Ruby)2. Scala3. (JavaScript)4. PHP5. Java 41. JavaNo reduce 42. PHP$array = array(1, 2, 3);function reduce($a, $b){ return $a + $b;};$sum = array_reduce($array, reduce);print $sum; 43. JavaScriptvar array = [1, 2, 3];var sum = array.reduce(function(a,b){return a + b});console.log(sum); 44. `for` is shorter... 45. Rubyarray = [1, 2, 3]sum = array.reduce(&:+)puts sum 46. Scalaval array = Array(1, 2, 3)val sum = array.reduce(_+_)println(sum) 47. (^-^) 48. One more thing... 49. More Scalaval array = Array(1, 2, 3)val sum = array.sumprintln(sum) 50. You learn everyday And you code gets BETTER 51. Are you a Java engineer? or maybe a PHP engineer? Do you use `Class? 52. Class Define a class in1. Scala2. (Ruby)3. PHP4. Java5. (JavaScript) 53. GreeterHello ScalaGreeter 54. Classes in Javapublic class Greeter {private String name;public Greeter(String name) {this.name = name;}public Greeter() {Greeter(Scala);}public String getName() {return this.name;}public void greet() {System.out.println(Hello + this.name);}}Greeter greeter = new Greeter("Scala!");greeter.greet(); 55. Classes in PHP 56. Classes in JSfunction Greeter(name) {this.name = typeof name == undefined ? Scala : name;}Greeter.prototype = { getName: function() {return this.name; }, greet: function() {console.log(Hello + this.name); }};var greeter = new Greeter(Scala);greeter.greet(); 57. Classes in Rubyclass Greeter attr_reader :name def initialize(name="Scala") @name = name end def greet puts Hello + @name endendgreeter = Greeter.new(Scala)greeter.greet 58. Classes in Scalaclass Greeter(val name: String = Scala) { def greet() { println(Hello + name) }}val greeter = new Greeter("Scala!");greeter.greet() 59. Really short? 60. YES!!!Really short? 61. break1/2http://pf.gree.jp/56616 62. Overview 63. Scala is General purpose Not only Web Multi-paradigm Object-oriented + Functionalprogramming 64. Scala Run on JVM A lot of Java libraries Hybrid language Imperative programming Object oriented programming Functional programming 65. Whats happy with FP Concurrency Scalability 66. Imperative vsFunctional Imperative Programmingdo A -> state++,do B -> state++, ... Functional programmingin1 -> f(x) -> out1in2 -> g(x) -> out2 67. + concurrency 68. Easy concurrency Imperative programmingdo A -> state sudden conflict!!! < Functional programmingin1 -> f(x) -> out1, in2 -> g(x) -> out2> no conflict!!! < 69. Dynamic vs Static typing About type-safety 70. Dynamic typing GOOD Run anyway BAD More runtime errors 71. NullPointerException 72. ReferenceError 73. TypeError 74. Call to undefined function 75. Static typing GOOD More compile errors BAD Hard to read error messages 76. Scala 2.10 We have Scala 2.9.3 Scala 2.10 is coming (on 12/26?) 77. Recommendation If you want to: write something other than Web app write noise-free, consise code develop your skill GRADUALLY 78. [Start] Scala!@mumoshu 79. Thank you! 80. Our bible 81. Scala for business Scala Java Scala 82. Scala for education sumScala 83. Scalas flexibility Scala 84. Learning Scala JavaJava Java WebPHP 85. REPL Scala ScalaREPLWelcome toScala ScalaScala 86. Compilation time Scala Time is money PC