What for to the person Scala?
Not so long ago we pre-printed book Oderski, Spoon and Venners about Scala ???. After all, before Scala 3 is still far away.
The author of today's article is Adam Worski, co-founder of SoftwareMill and an experienced Scala developer. He got an interesting summary of the strengths of the modern language Scala, which we offer to your attention.
plenary lecture Martin Oderski on ScalaDays, where he laid out plans for Scala 3 and plenary lecture John de Gous at the Scalapeño conference about the future of Scala in Scala community lively discussions continue. Apart from discussing these plenary speeches, numerous discussions are taking place in twitter, in the Slack communities, as well as on reddit (see eg .1 , .2 ).
That is the question!
All this is very interesting and informative for specialists already working in the Scala ecosystem. However, much of the debate is related to various intuitive or actual shortcomings of Scala as a language. These moments can frighten people "from the side", causing them questions: "Why should I even use Scala?", "What if this is a dead end?", "Will Scala 3 repeat the success of Python 3?", Etc. As in most discussions, attention is drawn to the weakest and most emotional theses, and this debate is no exception.
Therefore we'll take a step backwards : why would you even need Scala? What are the technical and business reasons for working with these languages?
Subject area of the project
To begin with, the Scala language is especially good for certain subject areas (but not for everyone!). The most important advantage of Scala is flexibility in the definition of abstractions . At your disposal - a number of the simplest "bricks" for this; Sometimes it is not more difficult to define an abstraction than to use a class, methods, and lambda expressions. Sometimes you have to use an implicit parameter or an extension method; In rare cases, it remains only to resort to macros. However, there are options .
Thus, Scala is perfect for you if you need navigate in a complex subject area . For example, it may be about distributed or competitive programming. To set up parallelism is very difficult, and Scala has a number of libraries that simplify this task by building abstractions. There are two main approaches for this: the actor, implemented with the help of Akka , and in the spirit of FP, represented by Monix / cats-effect and Scalaz / ZIO (if you wanted to read more about the comparison of these tools - I wrote series of articles on this topic).
However, of course, we can talk about other subject areas. Scala's capabilities also allow you to bring to a new level the modeling of typical business applications. But in this case we are talking about the complexity of another order. In the case of distributed systems, we are faced with technical complexity. When programming business logic in applications, we are talking about the complexity of the subject area as such. For example, in Debasish Ghosh's book " Functional and reactive domain modeling "Explains how to combine DDD with functional and reactive programming.
The complexity of the language is
Note: Speaking of Scala, everyone likes to emphasize the breadth of the possibilities of this language, emphasizing that it is because of this versatility that this language is so complex. This is not entirely true.
As mentioned above, Scala has a number of basic constructs from which abstractions can be collected. However, all of them can be combine with each other, thanks to which language and acquires such flexibility. Most innovative projects that you can come across are reduced to some combination of higher-order types, implicit parameters, and subtyping.
Thus, with a relatively small number of basic features (in terms of the size of the Scala grammar, it's easier with Kotlin, Java or Swift!) - which in turn makes learning easier - combinations are much more numerous.
Is not there too much choice? I do not think so. A programmer, as a competent and responsible professional, is more than able to choose the best option to solve a particular problem. For more details, see the article " Simple stack of Scala ".
Java, only better
Now many people say that Kotlin ousted Scala as "like Java, only better". But I believe that it's Scala, not Kotlin , still deserves such a title. There are two main reasons for this:
Firstly, Unchangeability in the Scala language is paramount . This is due to the nature of Scala itself: writing code on it is convenient primarily with the help of immutable data. These data include, in particular:
val(as units of the first class),
case-classes, functions of higher order, etc. But the point is also in how the standard library of the Scala language is designed and written; All data structures used by "default" are immutable. Thanks to the immutability, a whole series of things are simplified, especially in our highly competitive world, where those languages where invariability is preferred are won.
Secondly, in Scala is supported. type constructors, higher order types, and class types (declared implicitly), which greatly simplifies the work with wrapper /container types, for example, with
Task. Such wrappers predominate in programming in an asynchronous or reactive style, and the presence of language constructs that simplify the work, say, with a code base where
is actively used. Future- Another argument in favor of Scala.
What are class types? Their role is roughly the same as that of the design patterns in Java, however, they are more flexible and easier to use once you have a firm grasp of their meaning. On this occasion, there are several excellent guides, for example, 1 , 2 .
What about type constructors? These are such types as
Option, serving as "containers" or "wrappers" for other types. So, you can have
Future[Int]. Higher-order types allow writing code that abstracts any wrapper. See for example. 1 , 2 .
Suddenly you are wondering why you should resort to
Task? The point is not only that the majority of high-performance "reactive" computations with minimal delays are performed using asynchronous I /O, for which such designs are simply requested. Other reasons are given in this discussion on reddit and in my article " Why bother with wrappers? ".
Work in a predominantly immutable environment, as well as the ability to handle with ease such designs as
Task(and abstract them!) radically transforms your code. At first glance this may not be obvious: if you have the experience of Java or Ruby behind you, then you will not be able to realize these aspects of Scala right away. But even from the educational point of view it is useful to understand how the "functional" approach is organized and, what is more important, why it can turn out to be A very worthy alternative is .
Naturally, both Scala and Kotlin have a number of common advantages over Java, for example:
More compact syntax
Less stereotyped code
More saturated system of types
Absence of language ballast
At the same time, both languages open access to the ecosystem of libraries and JVM frameworks.
The more saturated the type system (in Scala it is richer than in Kotlin, and in Kotlin - richer than in Java), the more verification work is done by the compiler, rather than by the person. It is for this purpose that computers are created: to perform boring, routine repetitive tasks. Checking the applicability of types is definitely just one of these tasks.
The saturated type system is useful not only for writing code , but also, to a much greater extent at Reading code . When it's easy for you to navigate in the code base, understand what it does, and, besides, it's not terrible (or not so terrible) to take on his refactoring , this very positively characterizes the language both from a technical and an applied point of view.
OPF vs OOP
Another question often raised in such discussions is whether the Scala language should continue to adhere to the synthesis of the PLO and the OP, or develop along a purely functional path. I am supporter of synthesis. , especially because the FP and PLO are in my opinion - not alternative approaches, but complementing each other.
FP is programming using the functions , however, not any, but referentially transparent (see this response to reddit , in the earlier stage, where the referential transparency is excellent). In OOP, communication with objects is organized using "messages" or, in our terminology, calls of virtual methods. There is no reason why these two approaches could not coexist, and Scala has already demonstrated this!
In tweet about the merits of Scala John de Gouse mentions some features of OOP that are useful for a purely functional approach, in particular, modules of the first class (obtained by composing objects), the point syntax is (calling methods in objects) and classes / copies types as first-class constructions. All these are elements of a successful combination of the two paradigms. Maybe some more are just around the corner?
The "synthesis" project is not finished yet, there definitely remains a field for discussion. One of the unfinished aspects is the proposed syntax of extension methods, which should come to replace much more confused implicit transformations. Another is the optimization of the syntax of type classes; proposal on this subject , expressed some time ago, is clearly raw and does not cover some of the most common cases of using monads in Scala. Some suggestions are better, others need to be finalized, but it's good that they are coming, and discussions are about them; thanks to them, the language lives and, in the final analysis, it fixes the best solution.
Scala 3 will be released in two years. A number of interesting features will appear in it, in particular, opaque types, type parameters, a new approach related to metaprogramming, types of merging and intersections, implicit types of functions are just a few examples. Of course, there is (justified) concern about migration.
It is already known that a special tool for will be presented. automatic code migration with Scala 2 on Scala 3 using scalafix . Because Scala is a statically typed language, this task can be solved on a large scale and much easier than, for example, in Python. But, of course, there is no magic here: even if this tool provides 99% coverage, it will still be 1% of the most problematic cases. Since magic can not be counted, migration of these fragments will have to be done manually.
These are the costs of working with an actively developing language: you get the latest opportunities, but some of them are in fact not so good and in need of improvement. Even so, the proposed changes are not revolutionary. The language of Scala 3 is very similar to Scala ? no major paradigm changes are foreseen.
It is encouraging that the Scala team is serious about migrating. While earlier migration between older versions of Scala (eg from 2.8 to 2.9) was quite burdensome, the last migrations went much better. They involve three main parties: EPFL, ScalaCenter and Lightbend all of them (often together) work to facilitate migration. For example, there is a binary-compatible tool MIMA , as well as in the community are constantly creating numerous new libraries, designed to provide convenient work with the new versions of Scala.
Finally, until the finished tool TASTY (which, accordingly, can not yet be evaluated) should ensure the use of binary files from Scala 2 in Scala 3.
So, why use Scala?
So, what are the reasons to stop at Scala if we consider this language from the point of view of business? All of the above technical advantages are directly useful for business. When you have a language where you can write complex code with fewer bugs - then you are provided with minimal time delays, and satisfied users. If you write on Scala powerful, almost non-skidding competitive applications for which Scala provides special tools, this will turn out to be a significant benefit for your company.
In addition, do not forget about Spark , the leading platform for distributed data analysis . Scala is used not only to implement Spark itself, but also to determine the computations themselves. Here's another data science-oriented abstraction that hides a complex computational model.
Of course, Scala has problems, but where are they? The reason for optimism is that many people using Scala daily are actively working on improvement toolkit , libraries and the language itself. I can assume that they continue to work with Scala precisely because, with all the shortcomings, no language is so good for their subject area.
Scala allows you to develop your programming style, no matter what language you have been in before: Java, Ruby or just try yourself in programming. There is no uniquely advantageous approach to Scala; can be adhered to or more than imperative approach Akka, or more than functional the Cats and Scalaz approach.
This is where you can see the problem: in the Scala community there are fractions that adhere to the "reactive", "synthetic" OOP /OP approach and pure OP. However, in fact, this is a huge advantage. Due to this variety, discussions are held, many different opinions are expressed from different points of view. On this, in turn, it is excellent to learn non-standard solutions to problems and enrich your own tools.
Whatever path you choose in Scala, you will be supported by an impressive community of colleagues engaged in the development of libraries and frameworks; these people are always ready to help and discuss emerging ideas.
It may be interesting
I was facing some problems with my laptop and got stuck in that. This article helped me to solve these problems. I also want to take online writing help for writing the research paper of my doctorate. I took help from pendrago.com where I got many options for writing services so that we can choose our best one. I am really very impressed with this website friends. you also can try this. if you also have suggestions please let me know.
yes i am fully decided on amid this text and that i simply indulgent pronounce that this article is deeply best and pretty informative article.i will make hermetically sealed to be studying your blog extra. You made a fine lessening but I can't seasoned occurring but surprise, what kind of the including together facet? !!!!!!thank you!!!!!! Top places to visit in Venezia
After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.
New net web site is calling high-quality. thanks for the pleasant effort. Top places to visit
This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.