Is it Scala or Kotlin.... Kotlin or Scala.?

Is it Scala or Kotlin.... Kotlin or Scala.?

Scala and Kotlin are the two contender languages in the kingdom of JVM both of which is trying to bring better versions of Java and trying to overcome some of its limitations. They are the languages which are alike in dignity.

Scala is a popular language in functional programming providing strong static type system. It is designed to express programming patterns in concise, elegant and type safe ways. Even though Scala paved the way. It even saw pitfall in its popularity. Everybody thought Scala is going to be everywhere than java, and its gonna take over, it was too good but then it seems it has fallen. As most of the mainstream enterprise and mobile applications that's seen around mostly are from Spring platform these days. Probably Scala was too novel, too radical, and too functional back in days. But there is gonna phase of change that would be Scala 3.

Scala 3 would be a move towards realising the full potential of ideas that Scala has always pioneered i.e. fusion of object-oriented and functional programming in a typed setting. The main objectives of Scala 3 will be towards becoming more opinionated by promoting programming idioms, simplify wherever possible, eliminate inconsistencies & surprises, build strong foundations to ensure that design hangs well together, consolidate language constructs to improve the language’s consistency, safety, ergonomics, and overall performance.

Scala 3 has new compiler Dotty rewritten from scratch for speed and correctness. The language has been simplified supporting removal of redundant features. New features reflect importance of FP. There is new intermediate format TASTy (Typed Abstract Syntax Tree) into which Scala 3 codes compiles into. From this Java scripts, different versions of byte code etc. can be generated. Macros are implemented using TASTY Syntax Trees. There would also be lot of stuff that would be completely removed from Scala 3 like Symbol, and XML Literals, the Do While Loop, this qualifier etc.

The new features of Scala 3 includes:

1. Top level declarations. Its included for types, variables and functions within the file. No longer needs packaging things up in an object. Any function could be main using annotation @main.
 
2. No more need for new keyword. So another way of invoking a function was added using creator applications which lets you create an instance of a type without using keyword new and without the need to write an apply method. 

3. Extension methods was added. It helps in circumstances where one doesn't want to modify a type. So it helps in layering on an extra functionality to a type's and a feature that really helps in chaining multiple methods.
 
4. Enumerations are added to Scala 3 which was being implemented indirectly previously using case classes. Now we can use them in java style.
 
5. Implicits are replaced. They were used to abstract over a context, perform DI and implement Type Classes. But they could become dangerous if used incorrectly losing control over compiler what it is injecting.

6. Support for metaprogramming. It is comparatively better than macros. 

So Scala is catching up with Kotlin 
- by not using new keyword, 
- not using implicits, 
- having enumerated types, 
- having extension methods and 
- declaring top level types.


For domain driven design Scala 3 provides new ways to manipulate types.
 
It adds support for :

-- Union, 
-- Intersection, 
-- Literal Types and 
-- Opaque Type aliases. 

Hence a rich toolkit for describing data. 

Scala is catching up with F# in sense it also doesn't needs wrapper types either and supports union types.


Significant support for whitespaces.

This means one can omit braces at start of functions, conditions and iterations don't need braces within code. Hence the level of indentation is what that matters when braces are omitted.  

Something similar to Python especially when it comes to competing with Python in world of Machine learning.

Export Clauses that's an alternative added to Scala 3 to avoid Inheritance which violates encapsulation principle of OO by reusing functionality of a type by inheriting it. With export clauses its easy for one type to wrap up another without exposing it completely rather reusing selective functionality.

Kotlin on other hand as a language is quite contented with features it has and is quite a pragmatic language allowing programmers to deliver solutions effectively. It has substantial features that would be required for development. It is one of those JVM languages that cut through and provides exact stuff that would be productive. Its language that can build code faster and with higher quality to satisfy the needs of end-customers.

Features of Kotlin which made it sellable starting from 2011 to 2019 includes:

1. Null Safety
2. Shrinking Codebase
3. Elegant DSL's
4. Coroutines like F#, C# to handle asynchronous overflows.
5. Multiplatform Libraries - Take Kotlin and use it anywhere.

Kotlin 1.4 includes some significant features like functional interfaces (just like a DSL), serialisation is getting stabilised, WebAssembly, JS related stuff getting stabilised, Fast, uniform, pluggable compiler, improved type inference engine etc. Kotlin in future is trying to become universal solution for every platform. Kotlin is there for JVM, Android, JS, Native i.e. it is there for almost all the things.

Android really feels Kotlin is better. As it has following to offer :

1. Reduced Codebase
2. Simplified and cleaner code
3. Access FP features/patterns - Pull out features from Java.
4. Covers Android cracks
5. Unlikely to become obsolete in future

Kotlin is also being used in libraries like Spring boot which is Java based framework. So kotlin is getting everywhere and its a better language to write the code. To support multi platform libraries there is a common generic code which could be used for any of the platforms as business logic, DSLs. Thus it can be deployed as a native artefact, as a JS bundle for browser or node, as an executable, as a library or as a Jar for JVM.

So both Kotlin and Scala are like two separate ships sailing in sea in different directions passing by each other where each of them is trying to achieve quality but each of them is doing in different and specific manner. In Scala 3 the main focus is on the language to make it best possible in terms of features whereas in case of Kotlin the focus is to extend the language which could make it work on any platform & fit in with any projects. So even though both of them many times are trying to do same things but they are often in different directions. They are two different approaches with entirely different directions.

Programmers can go with Scala in projects which require a combination of functional and OOP programming style, where developers needs to handle lot of data and complex modelling. Whereas Kotlin becomes a language of choice for developers while developing apps which is comparatively less cumbersome as compared to other languages, with less lengthy codes and hence lesser the level of development frustration. So the trick would always be to find the right language that fits best for your requirements/problem in hand. A language that is comfortable for developers and compatible with end-goals of client project because both have common goals.

要查看或添加评论,请登录

Karuna Puri的更多文章

社区洞察

其他会员也浏览了