TL;DR I have created a script that would let you try out small snippet of Kotlin code from the terminal. So, you don't have to launch
intelliJ
to try out simple Kotlin code. I would like to know how you are trying out simple Kotlin code? Would you like to use the script? Or create one?
One thing I love about interpreted languages line Python is being able to try out a code snippet directly from the command line. In Python, you can either use the interactive shell or save it in a
.py
file and run it using
python script.py
.
However, when it comes to Kotlin the scenario is hugely different. Most of the times I have to launch
intelliJ
to understand the behaviour of a simple code. And launching an IDE is no joke. It takes a lot of time for starting and indexing. And if any extra dependency is needed we have to initialise a Gradle project for that. The web based Kotlin Playground is more convenient. But sadly we can't add any third party dependencies there.
I have always wanted something that would allow us to run a
.kt
file from the command line. But I couldn't find something like that.
But today I wrote a
python
script that allows me to run a Kotlin file from the command line.
For example,
Create a file with
.kt
extension and write some code in it.
// filename -> app.kt
fun main(){
println("Hello, world")
}
Then in the terminal type this,
>> kotlin app.kt
Hello, world // the output
I would like to know how you are trying out small snippets of Kotlin code. Would you be interested in a tutorial that would show you how to create this kind of script? Let me know π