中国科大60周年校庆返校,在USTC LUG分享的slides。

沈达发布于2018/12/10

注脚

展开查看详情

1.Scala在互联网金融中的应用

2.About Me 前 USTC LUG 活跃成员 GNU TeXmacs Contributor 挖财数据研发工程师 @sadhen on Github

3.About the Topic 1. Scala 是啥 ? 2. Scala 有哪些应用场景 ? 3. 如何学习 Scala ?

4.Scala 是啥

5.Scala/ScalaJS/Scala Native Scala combines object‑oriented and functional programming in one concise, high‑level language. Scala's static types help avoid bugs in complex applications, and its JVM and JavaScript runtimes let you build high‑performance systems with easy access to huge ecosystems of libraries.

6.Real World Scala on JVM Martin Odersky (EPFL) 瑞士洛桑理工: Generic Java (1998) first public Scala release (2004) Typesafe (2011) 2.11.0 (2014) Lightbend (2016) 2.12.0 (2016) 2.12.7 (Today?)

7.Apache Spark

8.Apache Spark RDD (Resilient distributed dataset) 《High Performance Spark》

9.Scala in Spark Core RDD: Scala Collection (Lazy)

10.Scala Collection: Immutability scala> 1 :: 2 :: 3 :: Nil res0: List[Int] = List(1, 2, 3) (1 (2 (3))) (car (1 (2 (3)))) => 1 (cdr (1 (2 (3)))) => (2 (3))

11.Scala Collection: Parallelism scala> (1 to 4).par.foreach(println) 2 1 4 3

12.Scala Collection: Lazyness 1. the magic lazy keyword 2. Stream (SICP) scala> def generate(starting: Int): Stream[Int] = { | starting #:: generate(starting + 1) | } generate: (starting: Int)Stream[Int] scala> println(generate(25)) Stream(25, ?) scala> println(generate(25).take(10).force) Stream(25, 26, 27, 28, 29, 30, 31, 32, 33, 34) scala> println(generate(25) .filter(_ % 2 == 0) .take(10) .toList ) List(26, 28, 30, 32, 34, 36, 38, 40, 42, 44)

13.Spark Catalyst

14.Enzyme SQL (挖财自研)

15.Scala in Spark SQL SQL: Pattern Matching 连城’s Talk at QCon Beijing 2015 https://github.com/liancheng/brainsuck case class Apple() case class Orange() case class Book() object ThingsAcceptor { def acceptStuff(thing: Any): Unit = { thing match { case Apple() ⇒ println("Thanks for the Apple") case Orange() ⇒ println("Thanks for the Orange") case Book() ⇒ println("Thanks for the Book") case _ ⇒ println(s"Excuse me, why did you send me $thing") } } }

16.Akka Actor Cluster Persistent ...

17.Akka Actor Actor是一种并发模型,但是Akka本质上是用Java的线程实现的。

18.import akka.actor._ class HollywoodActor() extends Actor { def receive: Receive = { case message ⇒ println(s"playing the role of $message") } } object CreateActors extends App { val system = ActorSystem("sample") val depp = system.actorOf(Props[HollywoodActor]) depp ! "Wonka" val terminateFuture = system.terminate() Await.ready(terminateFuture, Duration.Inf) }

19.case object Ping case object Pong class Pinger extends Actor { var countDown = 100 def receive = { case Pong ⇒ println(s"${self.path} received pong," + s" count down $countDown") if (countDown > 0) { countDown -= 1 sender() ! Ping } else { sender() ! PoisonPill self ! PoisonPill } } }

20.class Ponger(pinger: ActorRef) extends Actor { def receive = { case Ping ⇒ println(s"${self.path} received ping") pinger ! Pong } } val system = ActorSystem("pingpong") val pinger = system.actorOf(Props[Pinger], "pinger") val ponger = system.actorOf(Props(classOf[Ponger], pinger), import system.dispatcher system.scheduler.scheduleOnce(500 millis) { ponger ! Ping }

21.Akka Cluster Seed Node Fault Tolerance ... 让分布式系统触手可及!!!

22.Others Apache Kafka (Linkedin) 消息队列 Apache Flink (Alibaba Blink) 流式计算 Angel (腾讯) 机器学习 TransgorifyAI (AutoML) Chisel (FPGA) 硬件

23.如何学习Scala

24.推荐阅读 《Scala实用指南》(淘宝何品 Akka/Netty Contributor 译) 《Scala集合技术手册》(校友晁岳攀 原创) 《高性能Scala》(Thoughtworks 杨云 译) 《Spark Internals》 (中科院 Lijie Xu) 《Netty实战》 (何品 译) 《反应式设计模式》(何品、王石冲、邱嘉和 译, 未上市) 《Spark SQL内核剖析》 (腾讯原创) 《设计数据密集型应用》(影印本) 《高性能Spark》(影印本) 加粗的是看过的。

25.推荐阅读 《程序员的职业素养》

26.推荐Github @Atry (Thoughtworks) @hepin1989 (Taobao) @lihaoyi (Dropbox)

27.推荐课程 CSAPP FOPL GNU TeXmacs可以用来写作业,生成PDF。非常方便画二叉树、写 数学公式等等。

28.函数式编程 《Haskell 趣学指南》 《Haskell 函数式编程入门》(第二版) 《Scala 函数式编程》

29.参与开源社区 1. Github PR 2. GSOC 3. 相对严肃的项目会有邮件列表