欢迎大家赞助一杯啤酒🍺 我们准备了下酒菜:Formal mathematics/Isabelle/ML, Formal verification/Coq/ACL2, C++/F#/Lisp
Scala
小 (→Vim) |
小 (→版本) |
||
(未显示1个用户的86个中间版本) | |||
第1行: | 第1行: | ||
{{SeeWikipedia|Scala (programming language)}} | {{SeeWikipedia|Scala (programming language)}} | ||
[[Image:Scala-90x90.gif|right]] | [[Image:Scala-90x90.gif|right]] | ||
+ | [[文件:Lambda.jpg|right]] | ||
Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages. It is also fully interoperable with Java. The Scala distribution is released under a BSD-like license. | Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages. It is also fully interoperable with Java. The Scala distribution is released under a BSD-like license. | ||
第7行: | 第8行: | ||
==新闻== | ==新闻== | ||
+ | [[文件:Scala-logo.png|right]] | ||
*[http://www.scala-lang.org/node/8579 欧盟研究委员会将在未来五年向Scala 开发团队资助230万欧元] | *[http://www.scala-lang.org/node/8579 欧盟研究委员会将在未来五年向Scala 开发团队资助230万欧元] | ||
<rss>http://www.scala-lang.org/rss.xml|short|date|max=10</rss> | <rss>http://www.scala-lang.org/rss.xml|short|date|max=10</rss> | ||
第25行: | 第27行: | ||
More Detail: http://www.infoq.com/cn/Scala | More Detail: http://www.infoq.com/cn/Scala | ||
− | == | + | ==哲学== |
+ | 在Scala中,一切都是对象,即使是数值类型(一切值都是对象,一切函数都是值)。Scala更信奉万物皆应为对象。 | ||
+ | |||
+ | ==版本== | ||
+ | [http://docs.huihoo.com/scala/language-specification/ Scala语言规范] | ||
+ | *[https://scala-lang.org/blog/2021/05/14/scala3-is-here.html Scala 3 is here!] [https://docs.scala-lang.org/scala3/ Scala 3 Docs] | ||
+ | *[https://scala-lang.org/blog/2020/09/15/scala-3-the-community-powered-release.html Scala 3 - A community powered release] | ||
+ | *[http://docs.huihoo.com/scaladoc/scala/2.13 2.13] | ||
+ | *[http://docs.huihoo.com/scaladoc/scala/2.12 2.12] | ||
+ | *[http://docs.huihoo.com/scaladoc/scala/2.11 2.11] | ||
+ | *[http://docs.huihoo.com/scaladoc/scala/2.10 2.10] | ||
+ | |||
+ | ==SIP/SPP== | ||
+ | *[https://docs.scala-lang.org/sips/index.html Scala改进过程(Scala Improvement Process),语言及编译器进展] | ||
+ | *[https://scalacenter.github.io/platform/ Scala平台进程(Scala Platform Process), 社区驱动代码库的进展] | ||
+ | |||
+ | ==JDK== | ||
+ | [http://docs.scala-lang.org/overviews/jdk-compatibility/overview.html JDK Compatibility] | ||
+ | |||
+ | ===JDK 9=== | ||
+ | [https://github.com/scala/bug/labels/jdk9 JDK9 Issues] | ||
+ | |||
+ | ===JDK 8=== | ||
+ | |||
+ | ==指南== | ||
===OS X=== | ===OS X=== | ||
+ | 使用[[sdkman]]安装Scala或 | ||
sudo port install scala2.10 | sudo port install scala2.10 | ||
ls /opt/local/bin/scala* | ls /opt/local/bin/scala* | ||
第34行: | 第61行: | ||
$ scala | $ scala | ||
scala> :help | scala> :help | ||
+ | scala> (1 to 10) filter (_ % 2 == 0) map (_ * 2) reduce (_ * _) | ||
+ | res0: Int = 122880 | ||
+ | vim Hello.scala | ||
+ | object Hello { | ||
+ | def main(args: Array[String]) { | ||
+ | println("Hello, world!") | ||
+ | } | ||
+ | } | ||
+ | 运行 | ||
+ | scala Hello.scala 或 | ||
+ | scala> :load Hello.scala | ||
+ | 编译运行 | ||
+ | scalac Hello.scala && scala Hello | ||
===Eclipse=== | ===Eclipse=== | ||
第46行: | 第86行: | ||
===Vim=== | ===Vim=== | ||
+ | *[[ENSIME]] | ||
*[https://github.com/derekwyatt/vim-scala vim-scala] | *[https://github.com/derekwyatt/vim-scala vim-scala] | ||
===Emacs=== | ===Emacs=== | ||
+ | *[[ENSIME]] [https://github.com/ensime/ensime-emacs ENSIME Emacs] | ||
*[http://www.emacswiki.org/emacs/ScalaMode ScalaMode] | *[http://www.emacswiki.org/emacs/ScalaMode ScalaMode] | ||
+ | |||
+ | ==REPL== | ||
+ | $ scala | ||
+ | scala> object HelloWorld extends App { | ||
+ | | println("Hello, world!") | ||
+ | | } | ||
+ | defined object HelloWorld | ||
+ | scala> HelloWorld.main(null) | ||
+ | File IO | ||
+ | scala> import scala.io.Source | ||
+ | scala> val source1 = Source.fromURL("http://huihoo.com", "UTF-8") | ||
+ | scala> val lines = source1.getLines.toArray | ||
+ | scala> for (i <- 0 until lines.length) println(i + ": " + lines(i)) // 逐行打印 | ||
+ | |||
+ | ==容器Collection== | ||
+ | [http://docs.scala-lang.org/zh-cn/overviews/collections/introduction Scala Collection] | ||
+ | |||
+ | ===斐波那契数列=== | ||
+ | 使用了[http://docs.scala-lang.org/zh-cn/overviews/collections/concrete-immutable-collection-classes Stream(流)] 它与List类似,只不过其中的每一个元素都经过了一些简单的计算处理 #:: | ||
+ | scala> def fibFrom(a: Int, b: Int): Stream[Int] = a #:: fibFrom(b, a + b) | ||
+ | fibFrom: (a: Int, b: Int)Stream[Int] | ||
+ | scala> val fibs = fibFrom(1, 1).take(10) | ||
+ | fibs: scala.collection.immutable.Stream[Int] = Stream(1, ?) | ||
+ | scala> fibs.toList | ||
+ | res32: List[Int] = List(1, 1, 2, 3, 5, 8, 13, 21, 34, 55) | ||
+ | |||
+ | ===等价性=== | ||
+ | [http://docs.scala-lang.org/zh-cn/overviews/collections/equality 容器库有标准的等价性和散列法] | ||
+ | scala> List(1, 2, 3) == Vector(1, 2, 3) // true | ||
+ | scala> HashSet(1, 2) == TreeSet(2, 1) // ture | ||
+ | scala> Set(1, 2, 3) == List(1, 2, 3) // false | ||
+ | |||
+ | ===并行容器=== | ||
+ | [http://docs.scala-lang.org/zh-cn/overviews/parallel-collections/overview.html Scala标准库中包含的并行容器通过免去并行化的底层细节,以方便用户并行编程。] | ||
+ | val list = (1 to 10000).toList | ||
+ | list.map(_ + 42) // 顺序处理 | ||
+ | list.par.map(_ + 42) // 并行处理 | ||
+ | res2: scala.collection.parallel.immutable.ParSeq[Int] = ParVector(43, 44, 45 .... | ||
+ | |||
+ | ==并行并发== | ||
+ | *[http://docs.scala-lang.org/zh-cn/overviews/core/futures.html Future和Promise] | ||
+ | *[http://docs.scala-lang.org/zh-cn/overviews/parallel-collections/overview.html 并行容器] | ||
+ | *[http://docs.scala-lang.org/zh-cn/overviews/core/actors-migration-guide.html Actors迁移Akka] | ||
+ | |||
+ | ==元编程== | ||
+ | *[http://docs.scala-lang.org/overviews/reflection/overview.html 反射Reflection] | ||
+ | *[http://docs.scala-lang.org/overviews/macros/usecases.html 宏Macros] | ||
==[[Groovy]] and Scala== | ==[[Groovy]] and Scala== | ||
第57行: | 第146行: | ||
*Groovy与Scala若能走向统一, 将为Web开发者带来巨大的生产力 | *Groovy与Scala若能走向统一, 将为Web开发者带来巨大的生产力 | ||
− | ==[[Lift]]= | + | ==项目== |
− | + | [[scala ecosystem]] | |
+ | *[[sbt]] | ||
+ | *[[Apache Kafka]] | ||
+ | *[[Apache Spark]] | ||
+ | *[[Play framework]] | ||
+ | *[[Akka]] | ||
+ | *[[Scalatra]] | ||
+ | *[[Lift]]:Scala的Web框架 | ||
+ | *[[Scala.js]] | ||
+ | *[[Dropwizard]] | ||
+ | *[[Finagle]] | ||
+ | *[[Norbert]] | ||
+ | *[https://github.com/scalate/scalate Scalate] 模版引擎 | ||
+ | *[http://json4s.org/ json4s] [[JSON]] for Scala | ||
+ | *[https://github.com/twitter?language=scala Twitter]开发了不少Scala开源项目,Scala是Twitter使用的主要编程语言之一,[http://twitter.github.io/effectivescala/index-cn.html Effective Scala]是Twitter大量工程实践的总结,强力推荐。 | ||
+ | *[http://slick.lightbend.com/ Slick] Functional Relational Mapping for Scala | ||
+ | *[http://squeryl.org/ Squeryl] Scala ORM and DSL | ||
+ | *[[Lagom]] | ||
==[[.NET]]== | ==[[.NET]]== | ||
第66行: | 第172行: | ||
==用户== | ==用户== | ||
Twitter,Fouresquare以及LinkedIn,它们的Scala应用程序每天都要处理数十亿的Web事务。 | Twitter,Fouresquare以及LinkedIn,它们的Scala应用程序每天都要处理数十亿的Web事务。 | ||
+ | |||
+ | ==课程== | ||
+ | *[https://www.coursera.org/course/progfun Functional Programming, 函数式程序设计原理] | ||
+ | *[https://www.coursera.org/course/reactive Reactive Programming, 响应式程序设计原理] | ||
==文档== | ==文档== | ||
+ | *[http://docs.huihoo.com/javaone/2015/CON5331-Scala-in-the-Wild.pptx Scala in the Wild] | ||
+ | *[http://docs.huihoo.com/javaone/2015/CON6923-Finatra-The-Fast-Testable-Scala-Services-Framework-That-Powers-Twitter.pdf Finatra: The Fast, Testable Scala Services Framework That Powers Twitter] | ||
*[http://docs.huihoo.com/scala/scala-2012.pdf Scala:让Java平台上的编程重现生机] | *[http://docs.huihoo.com/scala/scala-2012.pdf Scala:让Java平台上的编程重现生机] | ||
+ | *[http://docs.huihoo.com/javaone/2014/BOF3024-Learning-Scala-A-Practical-Approach.pdf Learning Scala: A Practical Approach] | ||
+ | *[http://docs.huihoo.com/infoq/qconbeijing/2015/day1/scala-v-clojure.pdf Scala v. Clojure] | ||
+ | *[http://docs.huihoo.com/infoq/qconbeijing/2015/day2/scala-clojure-playing-nice.pptx Scala and Clojure
Playing Nice] | ||
+ | *[http://docs.huihoo.com/cufp/2013/Enabling-Microservice-Architectures-with-Scala.pdf Enabling Microservice Architectures with Scala] | ||
==图集== | ==图集== | ||
<gallery widths=100px heights=100px perrow=6> | <gallery widths=100px heights=100px perrow=6> | ||
+ | image:scala-class-hierarchy.jpg|类层次 | ||
+ | image:scala-type-hierarchy.png|类型层次 | ||
+ | image:scala-collection.png|scala.colection | ||
+ | image:scala-collection-immutable.png|scala.collection.immutable | ||
+ | image:scala-collection-mutable.png|scala.collection.mutable | ||
Image:java-and-scala.png|Java和Scala | Image:java-and-scala.png|Java和Scala | ||
Image:why-scala.png|Why Scala | Image:why-scala.png|Why Scala | ||
第77行: | 第198行: | ||
Image:typesafe-console.png|Typesafe控制台 | Image:typesafe-console.png|Typesafe控制台 | ||
image:eclipse-scala-2.11.2.png|Eclipse插件 | image:eclipse-scala-2.11.2.png|Eclipse插件 | ||
+ | image:Spark-Streaming-Cassandra-Kafka-and-Akka.png|技术堆栈 | ||
+ | image:play-framework-components.png|Play框架组件 | ||
</gallery> | </gallery> | ||
+ | |||
+ | ==关注== | ||
+ | [[image:java.png]] [[image:scala.png]] [[image:akka.png]] [[image:play.png]] [[image:spark.png]] [[image:slick.png]] [[image:lagom.png]] [[image:activator.png]] [[image:predictionio.png]] | ||
==链接== | ==链接== | ||
*http://www.scala-lang.org/ | *http://www.scala-lang.org/ | ||
+ | *[http://docs.huihoo.com/scala/language-specification/2.11/ Scala Language Specification] | ||
+ | *[http://docs.huihoo.com/scala/docs.scala-lang.org/zh-cn/ Scala中文文档] | ||
+ | *[https://github.com/lauris/awesome-scala Awesome Scala] [[image:awesome.png]] | ||
+ | *[http://qiujj.com/static/Scala-Handbook.htm Scala Handbook] | ||
+ | *[http://www.infoq.com/cn/articles/Scala-2-12-Only-Java8 Scala 2.12将只支持Java 8] | ||
*[http://docs.scala-lang.org/sips/ Scala Improvement Process] | *[http://docs.scala-lang.org/sips/ Scala Improvement Process] | ||
*http://docs.huihoo.com/scala/ | *http://docs.huihoo.com/scala/ | ||
第88行: | 第219行: | ||
*[http://www.infoq.com/cn/articles/guardian_scala Guardian.co.uk 从Java切换到Scala] | *[http://www.infoq.com/cn/articles/guardian_scala Guardian.co.uk 从Java切换到Scala] | ||
*[http://www.infoq.com/cn/articles/scala_and_spring Scala与Spring:强强联合] | *[http://www.infoq.com/cn/articles/scala_and_spring Scala与Spring:强强联合] | ||
− | *[http://twitter.github.com/scala_school/ Scala School] | + | *[http://twitter.github.com/scala_school/ Scala School]、[http://twitter.github.io/scala_school/zh_cn Scala 课堂(中文)] |
*[http://twitter.github.io/effectivescala/ Effective Scala],Twitter的Scala最佳实践。 | *[http://twitter.github.io/effectivescala/ Effective Scala],Twitter的Scala最佳实践。 | ||
*[http://developer.51cto.com/art/200907/134785.htm Groovy创始人:Java面临终结 Scala将取而代之] | *[http://developer.51cto.com/art/200907/134785.htm Groovy创始人:Java面临终结 Scala将取而代之] | ||
第94行: | 第225行: | ||
*[http://hongjiang.info/scala/ 在路上的Scala专题] | *[http://hongjiang.info/scala/ 在路上的Scala专题] | ||
*[https://github.com/alexandru/scala-best-practices/ Scala Best Practices] | *[https://github.com/alexandru/scala-best-practices/ Scala Best Practices] | ||
− | + | *[http://www.ibm.com/developerworks/cn/java/j-jn1/index.html Java 下一代: Groovy、Scala 和 Clojure] | |
− | + | *[https://github.com/lauris/awesome-scala Awesome Scala: 搜罗了当下主要的基于Scala开发的框架与工具] | |
+ | *[http://www.infoq.com/cn/articles/Scala-Series-Part-1 在大规模系统中使用Scala——Martin Odersky访谈(一)] | ||
+ | *[http://www.infoq.com/cn/articles/Scala-Design Scala的设计目标——Martin Odersky访谈(二)] | ||
+ | *[http://www.infoq.com/cn/articles/scala-type-system Scala类型系统的目的——Martin Odersky访谈(三)] | ||
+ | *[http://www.infoq.com/cn/articles/Scala-PatternMatching Scala模式匹配的亮点——Martin Odersky访谈(四)] | ||
+ | *[https://rocketeer.be/articles/concurrency-in-erlang-scala/ Concurrency in Erlang & Scala: The Actor Model] | ||
[[category:programming language]] | [[category:programming language]] | ||
+ | [[category:functional programming]] | ||
+ | [[category:lambda]] | ||
+ | [[category:concurrent computing]] | ||
+ | [[category:actor model]] | ||
[[category:java]] | [[category:java]] | ||
[[category:scala]] | [[category:scala]] | ||
[[category:twitter]] | [[category:twitter]] |
2021年8月11日 (三) 00:28的最后版本
您可以在Wikipedia上了解到此条目的英文信息 Scala Thanks, Wikipedia. |
Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages. It is also fully interoperable with Java. The Scala distribution is released under a BSD-like license.
目录 |
[编辑] 新闻
自http://www.scala-lang.org/rss.xml加载RSS失败或RSS源被墙
[编辑] 简介
Scala是一门现代的多范式编程语言,志在以简练、优雅及类型安全的方式来表达常用编程模式。它平滑地集成了面向对象和函数语言的特性。
- Scala是面向对象的:Scala是一个纯面向对象语言,在某种意义上来讲所有数值都是对象。对象的类型和行为是由class和trait来描述的。Class的抽象可由子类化和一种灵活的基于mixin的组合机制(它可作为多重继承的简单替代方案)来扩展。
- Scala是函数式的: Scala还是一个函数式语言,在某种意义上来讲所有函数都是数值。Scala为定义匿名函数提供了一种轻量级的语法,它支持高阶(higher- order)函数、允许函数嵌套、支持局部套用(currying)。Scala的case类及其内置支持的模式匹配模型代数类型在许多函数式编程语言中都被使用。
- Scala是静态类型的:Scala配备了一套富有表现力的类型系统,该抽象概念以一种安全的和一致的方式被使用。
- Scala是可扩展的:Scala的设计承认了实践事实,领域特定应用开发通常需要领域特定语言扩展。Scala提供了一个独特的语言组合机制,这可以更加容易地以类库的形式增加新的语言结构:
o 任何方式可以被用作中缀(infix)或后缀(postfix)操作符
o 闭包按照所期望的类型(目标类型)自动地被构造
两者结合使用可方便地定义新语句,无需扩展语法,也无需使用类似宏的元编程工具。
- Scala可与Java和.NET进行互操作:Scala 设计时就考虑了与流行编程环境良好交互,如Java 2运行时环境(JRE)和 .NET框架(CLR)。特别是与主流面向对象语言,如Java和C#尽量无缝交互。Scala有像Java和C#一样的编译模型(独立编译,动态装载类),允许访问成千上万的高质量类库。
More Detail: http://www.infoq.com/cn/Scala
[编辑] 哲学
在Scala中,一切都是对象,即使是数值类型(一切值都是对象,一切函数都是值)。Scala更信奉万物皆应为对象。
[编辑] 版本
[编辑] SIP/SPP
[编辑] JDK
[编辑] JDK 9
[编辑] JDK 8
[编辑] 指南
[编辑] OS X
使用sdkman安装Scala或
sudo port install scala2.10 ls /opt/local/bin/scala* sudo ln -s /opt/local/bin/scala-2.10 /opt/local/bin/scala vim /etc/paths , add /opt/local/bin $ scala scala> :help scala> (1 to 10) filter (_ % 2 == 0) map (_ * 2) reduce (_ * _) res0: Int = 122880
vim Hello.scala
object Hello { def main(args: Array[String]) { println("Hello, world!") } }
运行
scala Hello.scala 或 scala> :load Hello.scala
编译运行 scalac Hello.scala && scala Hello
[编辑] Eclipse
从 Eclipse Marketplace 中选择安装 The Scala IDE for Eclipse,来自 scala-ide.org。
从 Help > Install New Software ...
For Scala 2.11.2
http://download.scala-ide.org/sdk/helium/e38/scala211/stable/site
For Scala 2.10.4
http://download.scala-ide.org/sdk/helium/e38/scala210/stable/site
[编辑] Vim
[编辑] Emacs
[编辑] REPL
$ scala
scala> object HelloWorld extends App { | println("Hello, world!") | } defined object HelloWorld scala> HelloWorld.main(null)
File IO
scala> import scala.io.Source scala> val source1 = Source.fromURL("http://huihoo.com", "UTF-8") scala> val lines = source1.getLines.toArray scala> for (i <- 0 until lines.length) println(i + ": " + lines(i)) // 逐行打印
[编辑] 容器Collection
[编辑] 斐波那契数列
使用了Stream(流) 它与List类似,只不过其中的每一个元素都经过了一些简单的计算处理 #::
scala> def fibFrom(a: Int, b: Int): Stream[Int] = a #:: fibFrom(b, a + b) fibFrom: (a: Int, b: Int)Stream[Int] scala> val fibs = fibFrom(1, 1).take(10) fibs: scala.collection.immutable.Stream[Int] = Stream(1, ?) scala> fibs.toList res32: List[Int] = List(1, 1, 2, 3, 5, 8, 13, 21, 34, 55)
[编辑] 等价性
scala> List(1, 2, 3) == Vector(1, 2, 3) // true scala> HashSet(1, 2) == TreeSet(2, 1) // ture scala> Set(1, 2, 3) == List(1, 2, 3) // false
[编辑] 并行容器
Scala标准库中包含的并行容器通过免去并行化的底层细节,以方便用户并行编程。
val list = (1 to 10000).toList list.map(_ + 42) // 顺序处理 list.par.map(_ + 42) // 并行处理 res2: scala.collection.parallel.immutable.ParSeq[Int] = ParVector(43, 44, 45 ....
[编辑] 并行并发
[编辑] 元编程
[编辑] Groovy and Scala
- Scala和Groovy之间的核心区别在于前者是静态类型:静态类型是性能的关键,Scala的性能远高于Groovy
- Groovy的优势在于易用性以及与Java无缝衔接,Scala的优势在于性能和一些高级特性
- Groovy团队更注重实效思想而更Scala团队具有学术思想
- Groovy与Scala若能走向统一, 将为Web开发者带来巨大的生产力
[编辑] 项目
- sbt
- Apache Kafka
- Apache Spark
- Play framework
- Akka
- Scalatra
- Lift:Scala的Web框架
- Scala.js
- Dropwizard
- Finagle
- Norbert
- Scalate 模版引擎
- json4s JSON for Scala
- Twitter开发了不少Scala开源项目,Scala是Twitter使用的主要编程语言之一,Effective Scala是Twitter大量工程实践的总结,强力推荐。
- Slick Functional Relational Mapping for Scala
- Squeryl Scala ORM and DSL
- Lagom
[编辑] .NET
[编辑] 用户
Twitter,Fouresquare以及LinkedIn,它们的Scala应用程序每天都要处理数十亿的Web事务。
[编辑] 课程
[编辑] 文档
- Scala in the Wild
- Finatra: The Fast, Testable Scala Services Framework That Powers Twitter
- Scala:让Java平台上的编程重现生机
- Learning Scala: A Practical Approach
- Scala v. Clojure
- Scala and Clojure Playing Nice
- Enabling Microservice Architectures with Scala
[编辑] 图集
[编辑] 关注
[编辑] 链接
- http://www.scala-lang.org/
- Scala Language Specification
- Scala中文文档
- Awesome Scala
- Scala Handbook
- Scala 2.12将只支持Java 8
- Scala Improvement Process
- http://docs.huihoo.com/scala/
- Scala Style Guide
- http://download.huihoo.com/scala/
- Scala API
- Guardian.co.uk 从Java切换到Scala
- Scala与Spring:强强联合
- Scala School、Scala 课堂(中文)
- Effective Scala,Twitter的Scala最佳实践。
- Groovy创始人:Java面临终结 Scala将取而代之
- Why we love Scala at Coursera
- 在路上的Scala专题
- Scala Best Practices
- Java 下一代: Groovy、Scala 和 Clojure
- Awesome Scala: 搜罗了当下主要的基于Scala开发的框架与工具
- 在大规模系统中使用Scala——Martin Odersky访谈(一)
- Scala的设计目标——Martin Odersky访谈(二)
- Scala类型系统的目的——Martin Odersky访谈(三)
- Scala模式匹配的亮点——Martin Odersky访谈(四)
- Concurrency in Erlang & Scala: The Actor Model