应该学Scala这门语言吗?

很多人都听说过Scala这门语言,传到耳朵里的都是赞叹其语言的强大和优美。但Scala不是一门容易上手的语言,很多人包括公司都在思考是否要大规模使用Scala这门语言进行开发。每个人都有学习并使用Scala的原因,对于我来说,因为要开始写Spark的程序,学习Scala是很有必要的。我个人觉得,其实决定是否要学这门语言很简单,你只需要考虑两件事,工作中是否有需要,比如写Spark Jobs,第二就是在我业余的学习时间分配中,我是否还有时间分配来学这门语言。Scala从始至终很好的贯彻了functional programming的思想,而且这门语言对Java有很多借鉴和改进。在大数据横行的今天,学习这门语言不仅可以赶上趋势,而且还能彻底回顾Java这类JVM语言的知识。就算是作为业余的读物,我觉得也是非常值得学习的。
除了Scala,最近Kotlin这门语言也开始火了起来。至于选哪门语言开始,就因人而异了。

object HelloWorld {
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
  }
}

测试highlight.js对Scala语言支持

Scala从入门到精通

Scala的learning curve是非常长的,所以就连Scala的作者Martin Oderskey都特别撰文一篇细分了Scala从入门到精通的等级,下面是原文,对Scala有兴趣的或是Scala开发者们可以看看自己到什么级别了,然后继续打怪升级。

Scala levels: beginner to expert, application programmer to library designer

by the creator Martin Oderskey

Scala is a bit of a chameleon. It makes many programming tasks refreshingly easy and at the same time contains some pretty intricate constructs that allow experts to design truly advanced typesafe libraries. This means that, depending at what piece of code you look at, Scala might look very simple or very complex. But which pieces exactly are easy for beginners and which are more advanced? In the end, everybody will have their own yardstick. Nevertheless, I am trying here to give a rough categorization.
I hope this will help newcomers to the language decide in what order to pick subjects to learn, and that it will give some advice to teachers and book authors in what order to present the material.
I assume that programmers have already a good knowledge of Java, so we can take at least pre-generics Java 1.4 for granted. If that's not the case, some of the entry-level concepts such as classes and exceptions would need to be moved to more advanced levels.

Also, I distinguish between Scala application programmers and Scala library designers, because the required skill sets are really quite different. A first shot at a categorization has been discussed last month on the scala-debate mailing list. The current categorization incorporates some of the suggestions that were made then. So, here we go:

Level A1: Beginning application programmer

  • Java-like statements and expressions: standard operators, method calls, conditionals, loops, try/catch
  • class, object, def, val, var, import, package
  • Infix notation for method calls
  • Simple closures
  • Collections with map, filter, etc
  • for-expressions

Level A2: Intermediate application programmer

  • Pattern matching
  • Trait composition
  • Recursion, in particular tail recursion
  • XML literals

Level A3: Expert application programmer

  • Folds, i.e. methods such as foldLeft, foldRight
  • Streams and other lazy data structures
  • Actors
  • Combinator parsers

Level L1: Junior library designer

  • Type parameters
  • Traits
  • Lazy vals
  • Control abstraction, currying
  • By-name parameters

Level L2: Senior library designer

  • Variance annotations
  • Existential types (e.g., to interface with Java wildcards)
  • Self type annotations and the cake pattern for dependency injection
  • Structural types (aka static duck typing)
  • Defining map/flatmap/withFilter for new kinds of for-expressions
  • Extractors

Level L3: Expert library designer

  • Early initializers
  • Abstract types
  • Implicit definitions
  • Higher-kinded types

As I wrote above, the skill sets required from application programmers and library designers are really quite different. But if I should throw them into the same baskets, I would group like this:

  • A1, A2/L1, A3/L2, L3

That is, intermediate application programming is about on the same level of difficulty as junior library design, and advanced application programming is on the same level as senior library design.

To clarify: One can program very productively in Scala on level A1, which one should be able to pick up in a day or so, coming from Java. Mastering A2 will doubtlessly increase programmer productivity. A3 is for expert programmers with more specialized tasks, not everyone needs to get to that level. The same holds for library design. There are great libraries designed with the tools on level L1 and L2. Some libraries require L3 elements such as implicits and higher-kinded types, but a library does not automatically get better if it uses these elements -- often the opposite is true.

点击查看原文

其他

推荐作者本人的Scala书籍(第三版)
Programming in Scala, 3rd Edition Paperback – 31 May 2016 by Martin Odersky

Udemy的JVM原理课程
https://www.udemy.com/java-memory-management/

Scala面试问题
http://pedrorijo.com/blog/scala-interview-questions/

朋友Scala学习的收集贴
https://github.com/conorfennell/scala-zen