Let’s Use VS Code for Kotlin: A Mixed Bag Approach

Home » Kotlin » Let’s Use VS Code for Kotlin: A Mixed Bag Approach

When it comes to writing code in Kotlin, the first preference will be IntelliJ IDEA because JetBrains developed this super awesome language. Can I use VS Code for Kotlin? The answer is yes, but it requires a lot of effort to experience a moment of happiness.😀

Some developers always prefer the command line for Kotlin programming or practicing new features, while IDEs are good friends for those who are just starting off with a new language like Kotlin. We can also start learning Kotlin with a playground that is super helpful for those who don’t want to install any software while practicing Kotlin.

Let's Use VS Code for Kotlin: A Mixed Bag Approach

VS Code for Kotlin: Challenges

Possible? The answer is a resounding yes. While IntelliJ IDEA is the preferred choice, However, it’s crucial to note that setting up Visual Studio Code for Kotlin requires additional effort compared to the seamless integration offered by IntelliJ IDEA.

VS Code fans should be aware of some challenges. The setup process may require more manual configuration compared to IntelliJ IDEA, and certain advanced features might not be as readily available.

Install additional extensions to enhance the Visual Studio Code environment for Kotlin development. Some extensions may not include all features, such as linting and debugging support. This can be a limitation.

Setting up for Kotlin

Step 1: Open VS Code and Write a program

hellovs.kt

fun main() {

    val user = User()
    user.foo()
    user.message()
 }
 
 
 abstract class AbsClass {
     abstract fun foo()
     fun message() = println("Hello VS Code") 
 }
 class User() : AbsClass() {
     
     override fun foo(){
         println("Fun with VS Code") 
     }
 }

The IDE’s code area looks like the following:

Write a kotlin program inside visual studio code

You might have noticed that Visual Studio Code shows perfect Kotlin code highlighting. This can be achieved by using a VS Code extension called ‘Kotlin.

Kotlin Extension for VS Code :

kotlin extension for vs code

Step 2: Run a Kotlin Program in Visual Studio Code

Unfortunately, ‘kotlinc,’ the Kotlin compiler, does not work as expected. Therefore, I opted to utilize the default terminal in VS Code for compiling and running the Kotlin program.

Type in: Terminal (VS Code)

 kotlinc hellovs.kt -include-runtime -d hellovs.jar -verbose 

How to compile Kotlin code in VSCode? example

Let’s execute the program (binary version):

java -jar hellovs.jar

Let's run a kotlin program using java jar

In conclusion, the choice of using Visual Studio Code for Kotlin programming is viable, offering developers flexibility and the opportunity to work with a familiar and lightweight code editor.

Happy Coding!

You may also like...