Thoughts on using Kotlin to teach programming

Kotlin, initially announced in July 2011, is now fast replacing my use of Java for Android development. In this post I'll consider whether Kotlin could and should replace Java as a teaching language option at GCSE and A-Level.


I first became aware of Kotlin in the Spring/Summer of 2017. At the time I'd just finished writing my first Android application in Java for the AQA A-Level computing project. I became aware of Kotlin because Google had just announced that Kotlin would become an officially supported language for Android development. A few months later, Android Studio 3.0 was released. This version of the IDE was the first to include native support for Android development with Kotlin, although support had been available previously through the installation of a plugin. But why have I begun to use this new(ish) language over good old Java? What benefits does Kotlin bring to the table, not just for developing Android apps, but for teaching procedural and object-oriented programming as well?

The advantages of Kotlin with a focus on teaching

Firstly, in software engineering, being "multilingual" (i.e posessing the ability to write programs in many languages) is desirable. The majority of higher education courses in the UK teach Java at some point. Teaching Kotlin at GCSE and A-Level could help give students another language to add to their repertoire.

Secondly, compared with Java, Kotlin's syntax is far more concise. This makes it a somewhat less intimidating language for a new programmer. Consider the following "Hello World" example in Java:
public class HelloWorld {
    public static void main(String []args){
        System.out.println("Hello World");
The student is presented with access modifiers, classes, and the static and void keywords when they look at what is probably going to be the first Java program they run. Contrast that with the equivalent Kotlin:
fun main(args: Array) { 
    println("Hello World")
No access modifiers, classes, static or void keywords. Also note that a semi-colon isn't used at the end of the println("Hello, World") line (they're optional in Kotlin). In my view, Kotlin's syntax is less overwhelming for a beginner and provides other benefits such as allowing the concepts seen in the Java example like classes to be introduced slowly over time rather that all at once. I've seen many Java tutorials which introduce the above "Hello World" code and instruct the learner to ignore large parts of it. As someone who was a Java beginner very recently, this was frustrating and is far less necessary with Kotlin.

Thirdly, it's difficult to teach Java without teaching OOP. However, particularly at GCSE, you ideally need a language that will allow basic programming concepts to be taught whilst ignoring features like classes for the time being. Python (often used to teach programming basics) does this well. The problem with Python comes when you move onto teaching OOP because Python's implementation of classes is unlike many other languages.
In Kotlin, all you need to do to compile and run a program is declare a main function with some code inside. Kotlin is simpler to write for beginners compared to Java but also has an implementation of classes that is more like many other languages that the student is likely to move onto next.

A final point to note is that since Kotlin is a JVM* language, and JVM languages are compatible with each other, a Kotlin programmer can utilize the same libraries they used when writing Java programs directly from Kotlin. This makes learning how to use Kotlin easier for a teacher who's already an experienced Java programmer. For example, if you used the JavaFX library to create GUIs with your students you can use exactly the same library from Kotlin.

The drawbacks of replacing Java with Kotlin

I think the points made above illustrate that Kotlin could replace Java as an option at GCSE and A-Level and could even be a better teaching language whilst still being relatively familiar for teachers of Java. However, their are some drawbacks associated with replacing Java with Kotlin.

Firstly, a wealth of resources exist online for learning Java. Whilst some very good Kotlin resources exist**, it's far more likely that a student will come across a problem their having with Kotlin (for example, an error) that isn't yet well documented online.

Secondly, a teacher moving from Java to Kotlin may already have many resources written for their students in Java. A teacher may not have time for the amount of work associated with rewriting their resources.

Finally, although I've found learning Kotlin relatively straightforward it still takes time to get used to. It's understandable that a teacher might not want to invest time into learning Kotlin if Java is working perfectly well for them as a teaching language.

Concluding thoughts

From my experiences so far I think Kotlin has the potential to be a great teaching language. However, at this stage I think replacing Java with Kotlin would be ill-advised. It would seem to me that providing exam boards can do the work to temporarily support another programming language, it would be advantageous to support Kotlin, at least for long enough to assess in practice whether teaching programming concepts at GCSE and A-Level is easier in Kotlin. Whether it becomes a supported language or not it's interesting to note that even though the language is relatively young, many well-known companies are already using it in their codebases including Netflix, Pinterest and Uber***.


* JVM = Java Virtual Machine
** Notably the Kotlin website
*** According to the Jetbrains blog


Popular posts from this blog

How to complete your A-Level coursework and enhance your CV at the same time

Using Oxford Brookes University WIFI (eduroam) on a Linux machine