《The Rise and Fall of Scala》scala兴衰读后感

There seems to be a consensus in the Java community that the Scala programming language is already on the decline. I consider this a pity because I always enjoyed programming in Scala. Actually, I even started this blog to support alternative JVM languages like Scala. But the market has decided differently. Moshe Kranc has written an excellent analysis about the rise and fall of Scala. I found Moshe's article interesting enough to summarize it and to add a couple of thoughts of mine.

Before I start 

However, I've also read some of the 169 comments to Moshe's article, so I'd like to add a few words. First of all, I'm really fond of the Scala language. I'm not trying to write an anti-Scala article. Quite the contrary. I'm following the fate of Groovy and Scala for at least ten years now, and I'm still puzzled why the industry doesn't adopt one of these languages. In many aspects, both languages are clearly superior to Java.

Groovy is Java on steroids: it offers a host of useful features while remaining 99% compatible with Java. In fact, every Java programmer is a proficient Groovy programmer, they just don't know it.

Scala is a bit different because it doesn't try to be compatible with Java. Granted, there are (somewhat limited) compatibility and interoperability on the bytecode level, but the source code looks remarkably different. But that's simply the price you have to pay for a more flexible syntax, powerful type inference and much more. From a historical perspective, you can consider Java a radically simplified C++ dialect. Since the early days, the core Java language team added many features: Generic data types, lambda expressions, just to name a few. The Scala language was a pioneer for many of these features. Plus, it has been created as an academic greenfield project. I consider the result pretty convincing. For instance, this well-thought language design makes the powerful type inference possible.

So how come neither Groovy nor Scala have been widely adopted by the industry?

A couple of years ago I even proposed to use Scala as a first language for students and apprentices. However, that's not what happened. In my daily life, Scala hasn't made a big impact. It seems to be limited to certain areas like Spark, Akka, Gatling, and big data. It goes without saying that these niches are important, but as to my impression, the vast majority of programmers sticks to Java. That's a bit surprising taking in mind that Java has been considered the assembly language of the JVM universe by some. Java is fast, rock-solid and boring. Programmers are less productive than they are in Scala because Java is such a ceremonious language. But still. Recently I've read many tweets stating that Scala is declining again. Let's try to understand why. Moshe's article is a good starting point.

Why is Scala losing traction? 

Let me summarize his key points, adding my own thoughts along the way:

    • Scala brought functional programming to the Java world. Since version 8 Java itself caught up. So there's no need to abandon Java just to do functional programming. Personally, I disagree with this, because functional programming usually feels clumsy in Java. It's far from being a natural choice. So I usually deliberately avoid functional programming in Java, even when I happily embrace it when programming the same algorithm in TypeScript, Groovy or Scala. However, at the end of the day, it depends on the perception of the developers, and Lambda support seems to be convincing enough to stop them from learning a new programming language.
    • Scala is a challenging language that's not easy to master. That's something I noticed, too, and it's not helped by the esoteric vocabulary of the Scala community. I never grasped the meaning of "monad" in philosophy, but it seems to be a building block of functional programming. I had a lot of fun studying category theory at university. It's a slightly esoteric generalization of set theory. Interesting, but nothing you'll ever encounter in everyday life. Unless you start learning Scala. I've read quite of few blogs about categories in Scala. I suspect that using such exotic vocabulary repels many newbies.
    • The syntax of Scala is too flexible. In particular, there's operator overloading. Something I consider a great tool, but it has been used too often by many Scala framework programmers. I've seen entire frameworks consisting almost exclusively of methods bearing not a recognizable name, but a mathematical symbol. This allows for fast and efficient writing, but it makes it harder to understand the code, especially for the beginners. Plus, most operators are translated to methods taking the right-hand side expression as parameter, but it's also possible to define operators that are translated to methods called on the right-hand side, taking the left-hand side expression as a parameter. That's great, but it's also something you have to wrap your head around.
    • Moshe also reports a lack of compatibility with older versions of Scala and Java.

Compiler speed 

Another complaint I've often heard is the speed of the compiler. The idea of adopting Scala is to boost developer productivity, but the slow compiler often eats a substantial portion of that boost. Combined with the steep learning curve results in a frustrating user experience. Over time, the compiler has improved a lot, so I don't know if the speed of the compiler is still such an important issue as it used to be.

Community support 

This is a point I've noticed more than once, but I haven't used Scala often enough to be entirely sure. If you're one of the Scala developers trying hard to help newbies on StackOverflow, the following lines may seem a bit harsh. The Scala developer community is very active, but many ardent advocates of Scala have an annoying tendency to be overly convinced of their language. As far as I remember, I've read several reports complaining about the lack of community support for beginners. On the other hand, that's something where Java shines, especially on pages like StackOverflow or the Java code ranch, just to name a few. Recently, things are deteriorating, but for a long time, even stupid questions[1] were answered quickly and patiently. As to my perception, the Scala community indulges in the superiority of the language to such a degree that this euphoria shows in the forums as arrogance. Truth be told, in the early days, the Java community did the same mistake. Adopting Java after a couple of years of C programming resulted in such a productivity boost that it was hard not to commiserate with the C or C++ programmers. Can you imagine how difficult it was to write a program without a blue screen? Nowadays, blue screens have almost completely fallen into oblivion. They aren't associated with computer crashed. Instead, most people associate them with movie production.

Critical mass: Java is everywhere 

I guess there's at least one other important point. When Scala started to grow, the Java programming language already had reached a critical mass. No company wants to re-implement their entire code base. The promise of Scala is that there's no need to do such a thing because it runs on the JVM and peacefully cooperates with Java. Unfortunately, that's something managers have heard so often during their career that they consider it overly optimistic (to put it mildly). In this particular case, the marketing talk is mostly true, but from a manager's perspective, it's better to err on the safe side.

By the way, there's a similar critical mass on Windows desktop PCs and laptops. If I'm not mistaken, the vast majority of software targeting Windows is written in one of the Microsoft languages and IDEs, with the possible exception of games. Another example of a critical mass is PHP for web designers. Almost every web server, no matter how cheap, runs PHP. As a consequence, the major part of the internet consists of PHP pages.

Are there other sources of change? 

The ubiquity of Java in the enterprise means that it won't be replaced by a new programming language unless there's a paradigm shift. Functional programming was a paradigm shift, but it was too academic to be broadly accepted. However, we're currently living in the age of a major paradigm shift. The browser is becoming more and more important as a runtime environment. It's incredible how many devices come with a browser. Smartphones and tablet PCs are only the tip of the iceberg. So I don't expect major shifts on the backend side. Maybe a language like Kotlin is going to be the next big thing, but I doubt it. On the other hand, front-end programming is changing rapidly. The new hot programming language is actually a very old one: JavaScript. I hope it will be replaced by languages like TypeScript, but again, I doubt it. JavaScript already is ubiquitous. You can write a JavaScript program with a simple editor. TypeScript requires you to install several other programs first. You need a compiler, and to install the compiler, you have to install node.js and npm first. It seems most JavaScript programmers do this happily. But even so, it limits the ubiquity of TypeScript.

By the way, both TypeScript and JavaScript are functional programming languages, and adopting a functional programming style feels natural in these languages. Maybe that the heritage of Scala. It gave us a fresh impetus and new ideas that influenced the Java programming language a couple of years later.

According to Moshe, the Scala language is here to stay, at least in certain niches. It's the language of choice for many big data problems, and it's great for writing custom DSLs. The incredible flexibility of the syntax gives you a lot of freedom when you're designing a DSL. You can even write DSLs that read almost like a stilted, but natural English text. That's obviously not possible with Java. You can write a Java DSL without a lot of full stops, parentheses, and semicolons. That, in turn, means that you can't use such a DSL to communicate with the business department.

Wrapping it up 

Scala has played an important role in the evolution of Java and the JVM languages, but recently the popularity of Scala seems to dwindle for various reasons. What remains is the important heritage of Scala. Plus, it will persist in certain, even important niches. And who knows, maybe it's going to rise from such a niche at some time in future?

In particular, Gatling may attract a lot of curiosity to Scala again. It's an opportunity to get familiar with Scala without having to port the business logic from Java to Scala. The future is open!

Dig deeper 

Like said above, I recommend reading the article that inspired me to write this blog entry:

the rise and fall of Scala by Moshe Kranc

译文:

在Java社区中似乎已经达成共识,Scala编程语言已经在下降。我觉得很遗憾,因为我一直都很喜欢Scala编程。实际上,我什至开始创建该博客来支持其他JVM语言,例如Scala。但是市场决定有所不同。Moshe Kranc 对Scala的兴衰作了出色的分析我发现Moshe的文章很有趣,可以对其进行总结并添加一些我的想法。

在我开始之前 

但是,我还阅读了Moshe文章中的169条评论,因此,我想补充几句话。首先,我真的很喜欢Scala语言。我不是在写反scala的文章。恰恰相反。我至少在十年前一直跟踪Groovy和Scala的命运,但我仍然感到困惑,为什么该行业不采用其中一种语言。在许多方面,两种语言显然都优于Java。

Groovy是Java强化版本:它提供了许多有用的功能,同时仍与Java保持99%的兼容性。实际上,每个Java程序员都是精通的Groovy程序员,他们只是不知道。

Scala有所不同,因为它没有尝试与Java兼容。当然,在字节码级别上具有(有些限制)兼容性和互操作性,但是源代码看起来截然不同。但这仅仅是您必须为更灵活的语法,强大的类型推断等付出的代价。从历史的角度来看,您可以将Java视为一种完全简化的C ++方言。从早期开始,核心Java语言团队就添加了许多功能:通用数据类型,lambda表达式,仅举几例。Scala语言是其中许多功能的先驱。另外,它已被创建为学术性的新建项目。我认为结果令人信服。例如,这种经过深思熟虑的语言设计使强大的类型推断成为可能。

那么,Groovy和Scala为何都没有被业界广泛采用?

几年前,我什至提议使用Scala作为学生和学徒的第一语言。但是,事实并非如此。在我的日常生活中,Scala并没有产生太大的影响。它似乎仅限于某些领域,例如Spark,Akka,Gatling和大数据。毫无疑问,这些利基很重要,但是就我的印象而言,绝大多数程序员都坚持使用Java。考虑到Java被某些人视为JVM Universe的汇编语言,这有点令人惊讶。Java快速,坚如磐石且无聊。程序员的生产力不如Scala,因为Java是一种礼仪性的语言。但是还是。最近,我读了许多推文,指出Scala再次下降。让我们尝试了解原因。Moshe的文章是一个很好的起点。

为什么Scala不再流行? 

让我总结一下他的要点,并在此过程中添加自己的想法:

    • Scala将函数式编程带入了Java世界。从版本8开始,Java本身就流行起来。因此,不必为了进行函数式编程而放弃Java。我个人不同意这一点,因为函数式编程通常在Java中显得笨拙。这绝非自然选择因此,即使在TypeScript,Groovy或Scala中对同一算法进行编程时,即使我很乐意接受Java,我也通常会故意避免使用Java进行函数式编程。但是,归根结底,这取决于开发人员的看法,Lambda的支持似乎令人信服,足以阻止他们学习新的编程语言。
    • Scala是一种具有挑战性的语言,不易掌握。我也注意到了这一点,Scala社区的神秘词汇也无济于事。我从不理解哲学中“ monad”的含义,但这似乎是函数式编程的基础。我在大学里学习范畴论很有趣。这是对集合论的一点深奥的概括。有趣,但是您在日常生活中不会遇到任何事情。除非您开始学习Scala。我已经读过很多关于Scala中类别的博客。我怀疑使用这种奇特的词汇会排斥许多新手。
    • Scala的语法过于灵活。特别是操作员超载。我认为这是一个很棒的工具,但是许多Scala框架程序员经常使用它。我已经看到整个框架几乎全部由方法组成,这些方法的名称不是可识别的名称,而是数学符号。这样可以进行快速有效的编写,但是这会使理解代码变得更加困难,尤其是对于初学者而言。另外,大多数运算符都转换为以右侧表达式为参数的方法,但是也可以定义运算符,这些运算符以左侧表达式为参数,转换为在右侧调用的方法。太好了,但这也是您必须缠住脑袋的事情。
    • Moshe还报告说与旧版本的Scala和Java不兼容。

编译速度 

我经常听到的另一个抱怨是编译器的速度。采用Scala的想法是为了提高开发人员的生产力,但是速度慢的编译器通常会吃掉大部分的提升。结合陡峭的学习曲线会导致令人沮丧的用户体验。随着时间的流逝,编译器已经有了很大的改进,所以我不知道编译器的速度是否仍然像以前那样重要。

社区支持 

我已经不止一次注意到这一点,但是我并没有经常使用Scala来完全确定。如果您是努力在StackOverflow上帮助新手的Scala开发人员之一,那么以下几行可能看起来有些苛刻。Scala开发人员社区非常活跃,但是许多Scala的拥护者都倾向于过度相信自己的语言。据我所记得,我读过几份报告,抱怨缺乏对初学者的社区支持。另一方面,这是Java的亮点,尤其是在StackOverflow或Java代码ranch之类的页面,仅举几例。最近,情况正在恶化,但是很长一段时间,甚至是愚蠢的问题]被迅速而耐心地回答。据我所知,Scala社区沉迷于语言的优越性,以至于这种欣快感在论坛上显示为傲慢。说实话,在早期,Java社区犯了同样的错误。经过几年的C编程后才采用Java,从而大大提高了生产率,以至于很难不与C或C ++程序员同情。您能想象在没有蓝屏的情况下编写程序有多么困难吗?如今,蓝屏几乎已完全被遗忘。它们与计算机崩溃无关。相反,大多数人将它们与电影制作联系在一起。

临界质量:Java无处不在 

我想至少还有一个重要的观点。当Scala开始发展时,Java编程语言已经达到了极限。没有公司愿意重新实现其整个代码库。Scala的承诺是不需要做这样的事情,因为它运行在JVM上并与Java和平协作。不幸的是,经理们在职业生涯中经常听到这样的话,他们认为这过于乐观了(说得有些客气)。在这种情况下,市场营销的话大部分是正确的,但从经理的角度来看,最好还是谨慎一点。

顺便说一句,在Windows台式机和笔记本电脑上也有类似的临界质量。如果我没记错的话,绝大多数针对Windows的软件都是用Microsoft语言和IDE之一编写的,可能是游戏除外。临界质量的另一个例子是针对网页设计师的PHP。几乎每台Web服务器,无论价格多么便宜,都运行PHP。结果,互联网的主要部分由PHP页面组成。

还有其他变化来源吗? 

Java在企业中无处不在,意味着除非发生范式转变,否则它不会被新的编程语言所取代。函数式编程是一种范式转换,但是它太学术化而不能被广泛接受。但是,我们目前正处于重大范式转变的时代。浏览器作为运行时环境变得越来越重要。令人难以置信的是,浏览器附带多少设备。智能手机和平板电脑只是冰山一角。因此,我不希望后端发生重大变化。也许像Kotlin这样的语言将成为下一个大问题,但我对此表示怀疑。另一方面,前端编程正在迅速变化。新的热门编程语言实际上是一种非常古老的语言:JavaScript。我希望它将被TypeScript之类的语言取代,但是我再次对此表示怀疑。JavaScript已经无处不在。您可以使用简单的编辑器编写JavaScript程序。TypeScript要求您首先安装其他几个程序。您需要一个编译器,并且要安装该编译器,必须先安装node.js和npm。看来大多数JavaScript程序员都会很高兴地做到这一点。但是即使如此,它仍然限制了TypeScript的普遍性。

顺便说一下,TypeScript和JavaScript都是函数式编程语言,在这些语言中采用函数式编程风格是很自然的。也许是Scala的传承。几年后,它为我们带来了新的动力和新思想,这些思想和思想影响了Java编程语言。

根据Moshe的说法,Scala语言将在至少某些特定领域保持存在。它是许多大数据问题的首选语言,并且对于编写自定义DSL非常有用。语法令人难以置信的灵活性为您在设计DSL时提供了很大的自由度。您甚至可以编写几乎读起来像是高效但自然的英语文本的DSL。Java显然不可能做到这一点。您可以编写Java DSL,而无需使用许多句号,括号和分号。反过来,这意味着您不能使用这种DSL与业务部门进行通信。

总结

Scala在Java和JVM语言的发展中起了重要作用,但是最近由于各种原因,Scala的流行似乎在减少。剩下的就是scala的重要遗产。另外,它将持续存在某些甚至重要的领域。谁知道,也许将来某个时候它会从这种利基市场中崛起?

特别是,Gatling可能再次吸引了Scala的好奇心。这是一个熟悉Scala的机会,而无需将业务逻辑从Java移植到Scala。未来是开放的!

深入挖掘 

就像上面说的,我建议阅读启发我写这篇博客文章的文章:

Scala的兴衰 Moshe Kranc

posted @ 2020-05-20 09:31  wqbin  阅读(241)  评论(0编辑  收藏  举报