nilTheDev
12/19/2021, 2:45 PMintelliJ
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 🙂Big Chungus
12/19/2021, 3:01 PMnilTheDev
12/19/2021, 3:07 PMBig Chungus
12/19/2021, 3:09 PMnilTheDev
12/19/2021, 3:11 PMJavier
12/19/2021, 4:18 PMkotlinc —script
and just kotlin
? I just use kotlin
with no issues to run scriptsBig Chungus
12/19/2021, 4:20 PMIgnat Beresnev
12/19/2021, 9:57 PMnkiesel
12/20/2021, 9:24 AMBig Chungus
12/20/2021, 9:47 AMalias kshell ki
🧌Matteo Mirk
12/22/2021, 10:31 AMkotlinc -script myFile.kts
with single dashBig Chungus
12/22/2021, 10:33 AMMatteo Mirk
12/22/2021, 10:41 AM