Kotlin vs. Groovy: Which Language to Choose
Tags: Kotlin, Software Development, Java, Programming, Programming Languages

Application of Computer Science to a growing range of fields and general advancements in technologies push programming languages to constant improvement and adaptation to the present-day needs. Now we have a bunch of languages serving different purposes: some of them emerged as an independent project, while others bud off from established and well-known languages.

The colossus of Java, for example, has a number of offspring; some of them have proved to be a success. One of them, Kotlin, was backed by Google as the official language for Android development in 2017 and was reported to be the second most loved and wanted programming language in 2018 Stack OverFlow survey and remains in Top 5 in this year’s survey. Another successful member of Java-based languages is Groovy that is gaining popularity among developers. At the same time, the 2018 Stack OverFlow survey listed Groovy among the most dreaded languages. In this setting, it seems unfair to compare the languages, but let’s see whether Groovy is so dreadful compared to Kotlin and, generally, which of them to choose as another addition to your bag of skills.

Overview

Kotlin

Kotlin is developed by Jetbrains — a company well-known in the Java world for its IDE named IntelliJ IDEA — and open sourced in 2012. It is a high-level, statically typed programming language that runs on Java Virtual Machine (JVM) and can be compiled to JavaScript source code or handle the LLVM compiler infrastructure.

Though internally Kotlin is reliant on the present Java Class library, its syntax may not be specifically compatible with Java. Kotlin has aggressive type inference to decide the type of values and expressions for which type has been left unstated. This makes it less verbose comparing to Java.

Kotlin has a practical mix of features from Java, C# and other new languages. It generally shows many improvements over Java such as null safety or operator overloading, though lacking certain convenient Java properties such as ternary operator and checked exceptions. However, both languages are completely interoperable, so they can co-exist in the same application.

Besides, since Android Studio 3.0 (published in October 2017), Kotlin is also part of the Android SDK and is involved in the IDE’s installation package as an option to the standard Java compiler. The Android Kotlin compiler allows user to target Java 6, Java 7, or Java 8-compatible bytecode.

Kotlin is much appreciated by developers for its interoperability, code security, and accuracy.

Groovy

Groovy is an object-oriented programming language for Java platform that is distributed through the Apache License v 2.0.

The key feature of Groovy is that it aspires to combine the best of two worlds: it supports both static typing typical for Java and more relaxed dynamic typing similar to that of Python.

Moreover, it can be used as both a programming language and a scripting language for the Java Platform. Like Kotlin, Groovy is compiled to Java Virtual Machine (JVM) bytecode and interoperates seamlessly by different Java code and libraries.

Generally speaking, Groovy has a Java-like syntax, but it takes on the ease of more moldable languages, such as Python and Ruby. Groovy can be called a modern Java enhancer, since it provides greater flexibility and introduces special features to applications, such as safe navigation operator (?.), the concept of Closures, Traits, runtime dispatching of methods, Groovy String, Array initialization and many others.

Groovy is a testing-oriented development language with syntax that supports running tests in IDEs, and Java build tools like Ant or Maven. Besides, it provides native support for markup languages like XML and HTML and domain specific languages.

What can also make it attractive to developers is its short learning curve: for Java developers, it is just a step away from the usual syntax, for new learners — it is relatively easy and modern.

Applications

Kotlin

Given the fact that Kotlin as an official Android development language at Google I/O, its most obvious application is Android development.

Speaking more generally, Kotlin is great for developing server-side applications, allowing developers to write concise and expressive code while maintaining full compatibility with existing Java-based technology stacks.

The most prominent applications of Kotlin are rather impressive and include the following giants:

Pinterest moved away from Java to Kotlin for their Android Application Development Gradle built developing android files (APK files) for both IDEA and Eclipse Evernote integrated Kotlin in their android client Coursera built an online courses application for a range of courses Uber made internal tooling processes on Kotlin Atlassian and Trello did a full code conversion of the old codebase. Kickstarter helps find resources for people showcasing creativity.

Groovy

Since Groovy is so similar to Java, it is sometimes difficult to find a distinguishing application for it. One thing that is a definite benefit is that Groovy enables to write scripts besides classes, so you can write applications and scripting with the same language. Groovy scripts are a perfect fit for tasks that change often. Since Groovy is a part of JMeter distribution, it is a good idea to use it for scripting and possibly to migrate the scripting logic developed in other scripting languages, to Groovy.

Examples of using Groovy as a scripting language are rather numerous:

1. Netflix uses Groovy for server-side scripting to offer various levels of filtering Besides, Netflix Spinnaker is implemented in Groovy.

2. Oracle’s fusion middleware is using Groovy scripts in its business component suite.

3. LinkedIn use Groovy also in their “Glu” open source deployment & monitoring automation platform.

The other direction of practical applications for Groovy is to use it as an embedded business language (a Domain-Specific Language):

1. National Cancer Institute uses it to do scientific simulations

2. JPMorgan, MasterCard and other financial institutions use Groovy for its nice DSL capabilities.