Scala

2,134 views

Published on

2012-2-26珠三角沙龙

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

No Downloads
Views
Total views
2,134
On SlideShare
0
From Embeds
0
Number of Embeds
660
Actions
Shares
0
Downloads
28
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Scala

    1. 1. Sparkle
    2. 2. 大纲Scala是什么语法(特色)类库和工具缺点
    3. 3. Scala是什么
    4. 4. "Which Programming Language would you use *now* on top of JVM, except Java?". The answer was surprisingly fast and very clear: - Scala. http://www.adam-bien.com/roller/abien/entry/java_net_javaone_which_programming
    5. 5. I can honestly say if someone had shown me theProgramming in Scala book by by MartinOdersky, Lex Spoon & Bill Venners back in 2003 Id probably have never created Groovy. http://macstrac.blogspot.com/2009/04/scala-as-long-term-replacement-for.html
    6. 6. Scala是……
    7. 7. Scala是……又一个JVM上的语言(编译)
    8. 8. Scala是……又一个JVM上的语言(编译)强类型
    9. 9. Scala是……又一个JVM上的语言(编译)强类型“动态的”静态语言
    10. 10. Scala是……又一个JVM上的语言(编译)强类型“动态的”静态语言函数式
    11. 11. Scala是……又一个JVM上的语言(编译)强类型“动态的”静态语言函数式面向对象
    12. 12. 谁在用TwitterLinkedInFourSquareXerox、Sony、Siemens
    13. 13. 语法(特色)
    14. 14. Hello world! object Test { ! def main(args: Array[String]) { ! ! println("Hello, world!") ! } }
    15. 15. Hello world!没有分号 object Test { ! def main(args: Array[String]) { ! ! println("Hello, world!") ! } }
    16. 16. Hello world!没有分号 object Test {定义后置 ! def main(args: Array[String]) { ! ! println("Hello, world!") ! } }
    17. 17. Hello world!没有分号 object Test {定义后置 ! def main(args: Array[String]) { ! ! println("Hello, world!")object ! } }
    18. 18. Hello world!没有分号 object Test {定义后置 ! def main(args: Array[String]) { ! ! println("Hello, world!")object ! } }def
    19. 19. Hello world!没有分号 object Test {定义后置 ! def main(args: Array[String]) { ! ! println("Hello, world!")object ! } }defprintln
    20. 20. Hello world! object Test extends Application { ! println("Hello, world!") }
    21. 21. Hello world! object Test extends Application { ! println("Hello, world!")extends }
    22. 22. Hello world! object Test extends Application { ! println("Hello, world!")extends }类内直接写代码
    23. 23. 简化
    24. 24. 简化val i = 1.2.toInt
    25. 25. 简化val i = 1.2.toIntval list = List(1, 2, 3)
    26. 26. 简化val i = 1.2.toIntval list = List(1, 2, 3)val map = Map("Guangzhou" -> "GZ","Shenzhen" -> "SZ")
    27. 27. 简化val i = 1.2.toIntval list = List(1, 2, 3)val map = Map("Guangzhou" -> "GZ","Shenzhen" -> "SZ")class MyClass(x: Int, y: Int) {}
    28. 28. 简化val i = 1.2.toIntval list = List(1, 2, 3)val map = Map("Guangzhou" -> "GZ","Shenzhen" -> "SZ")class MyClass(x: Int, y: Int) {}list.exists(_ == 2) //true
    29. 29. 简化val i = 1.2.toIntval list = List(1, 2, 3)val map = Map("Guangzhou" -> "GZ","Shenzhen" -> "SZ")class MyClass(x: Int, y: Int) {}list.exists(_ == 2) //trueval (a, b, _) = (x, y, z)
    30. 30. 函数式编程
    31. 31. 函数式编程list.filter(e => e % 2 == 0)
    32. 32. 函数式编程list.filter(e => e % 2 == 0)list.filter(_ % 2 == 0)
    33. 33. 函数式编程list.filter(e => e % 2 == 0)list.filter(_ % 2 == 0)val f = (e: Int) => e % 2 == 0list.filter(f)
    34. 34. open class(ruby)class String def foo "foo" endendputs "".foo # prints "foo"
    35. 35. 为什么我们需要open class
    36. 36. 为什么我们需要open class StringUtils.isBlank("some str")
    37. 37. 为什么我们需要open class StringUtils.isBlank("some str") "some str".isBlank
    38. 38. 为什么我们需要open class StringUtils.isBlank("some str") "some str".isBlank myObj should not contains(13)
    39. 39. 隐式转换class MyString(str: String) { def isBlank = str.trim.length == 0}implicit def myStringWrapper(str: String) = newMyString(str)println("some str".isBlank)
    40. 40. 隐式转换class MyString(str: String) { def isBlank = str.trim.length == 0}implicit def myStringWrapper(str: String) = newMyString(str)println("some str".isBlank) println(new MyString("some str").isBlank)
    41. 41. open class的效果让大家觉得Scala是动态语言,但选择 隐式转换来实现,正好证明了Scala是静态语言
    42. 42. Trait class Animal { xxx } trait CanFly { def fly { println("fly") } } class Bird extends Animal with CanFly {}
    43. 43. Trait class Animal { xxx } trait CanFly {Mixin,类似多集成 def fly { println("fly")接口和实现一起出现 } }是什么和拥有什么功能 class Bird extends Animal with CanFly {}
    44. 44. Traitclass Fish { xxx }trait CanFly { def fly { println("fly") }}val flyFish = new Fish with CanFly
    45. 45. Actorsval myActor = actor { loop { react { case "Send" => { println("Get") } } }}myActor ! "Send"
    46. 46. 模式匹配def matchTest(x: Any) = x match { case 1 => "number one" case y: Int if y > 0 => y + 1 case head :: tail => tail case Send(a, _) => a case ("Send", _, b: String) => b case _ => x}
    47. 47. XML支持println(<date>{new java.util.Date()}</date>)
    48. 48. 并发
    49. 49. 是什么让我们觉得一个语言是并发的语言
    50. 50. 是什么让我们觉得Go和Erlang是并发语 言,而C++和Python不是
    51. 51. 是什么让我们觉得Go和Erlang是并发语 言,而C++和Python不是 Go内置Channel和Goroutine Erlang的一次赋值、轻量级进程
    52. 52. 是什么让我们觉得Scalavalcase class模式匹配大量的immutable类Actors
    53. 53. 与Java互相调用Scala能调用绝大部分的JavaJavaConverters、JavaConversionsJava调用Scala独有的东西比较困难
    54. 54. 类库和工具
    55. 55. Liftfull stackview first
    56. 56. Play!Play Scala
    57. 57. Play!Play ScalaPlay 2.0 !!
    58. 58. AkkaSTM & TransactorsFault-toleranceTransparent RemotingScala & Java API
    59. 59. sbt构建工具
    60. 60. 更多XitrumScalatra、ScalateScalaTest、specs2Squeryl
    61. 61. IDE支持
    62. 62. 缺点
    63. 63. It took about 15 hours to recreate the publishingdaemon in Clojure and get it to pass all our tests. Today we ran a "soak test" publishing nearly300,000 profiles in one run. The Scala code wouldfail with OoM exceptions if we hit it with 50,000 profiles in one run (sometimes less). http://groups.google.com/group/clojure/browse_thread/thread/b18f9006c068f0a0
    64. 64. The e-mail confirms that Yammer is moving its basicinfrastructure stack from Scala back to Java, owing to issues with complexity and performance. http://www.infoq.com/news/2011/11/yammer-scala
    65. 65. flatMap [B, That] (f: (A) Traversable[B])(implicit bf: CanBuildFrom[List[A], B, That]) : That http://goodstuff.im/yes-virginia-scala-is-hard
    66. 66. jetbrains出了新JVM语言Kotlin后,Scala社区终于 始 正视Scala太 杂的问题了 http://groups.google.com/group/scalacn/browse_thread/thread/cbbe5997009db919
    67. 67. 缺点编译速度二进制不兼容语法越来越 杂太少人使用,招聘 发人员的问题
    68. 68. 始使用
    69. 69. 始使用使用最新版(2.9.1)
    70. 70. 始使用使用最新版(2.9.1)先 用高级特性
    71. 71. 始使用使用最新版(2.9.1)先 用高级特性小工具、单元测试
    72. 72. 始使用使用最新版(2.9.1)先 用高级特性小工具、单元测试Java/Scala混合项目,逐步 移
    73. 73. 始使用使用最新版(2.9.1)先 用高级特性小工具、单元测试Java/Scala混合项目,逐步 移sbt
    74. 74. 谢谢weibo&twitter: @sparklezengemail: popeast@gmail.comwebsite: http://weavesky.com

    ×