TL;DR I have created a script that would let you t...
# feed
n
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.
Copy code
// filename -> app.kt

fun main(){
    println("Hello, world")
}
Then in the terminal type this,
Copy code
>> 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 ๐Ÿ™‚
๐Ÿ†’ 3
b
Well you can run .kts file from cmdline as well kotlinc --script myFile.kts
โž• 1
There's also idea light for quick edits idea -e myFile.kt
โž• 1
n
@Big Chungus Wow! I wish I knew it earlier! Thank you so much ๐Ÿค—๐Ÿค—๐Ÿค— It's really cool.
b
Not trying to diminish your work here. Just wanted you to be aware of alternatives out there ๐Ÿ˜€
n
Had I known this earlier I wouldn't even have taken the pain to write the script ๐Ÿ˜…
j
what is the difference between
kotlinc โ€”script
and just
kotlin
? I just use
kotlin
with no issues to run scripts
b
kotlinc --script works on all .kts files, kotlin requires .main.kts
๐Ÿ‘ 4
i
n
I still think "ki shell" should be called "kshell" for all the Java converts among us...
b
alias kshell ki
๐ŸงŒ
๐Ÿ˜‚ 1
โ˜๏ธ 1
m
@Big Chungus you have a typo in your first advice, it should be
Copy code
kotlinc -script myFile.kts
with single dash
b
Ah, yes. Kotlin adopted those shitty java options instead of UNIX...
m
Lol I know, I was upset too ๐Ÿ˜„
@nilTheDev no effort wasted here: you learned something anyway in the process: how to make it work using Python and the existing alternatives. I learned a lot from this thread too, so itโ€™s good for everyone! ๐Ÿ‘
๐Ÿ™ƒ 1