https://kotlinlang.org logo
#feed
Title
# feed
n

nilTheDev

12/19/2021, 2:45 PM
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

Big Chungus

12/19/2021, 3:01 PM
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

nilTheDev

12/19/2021, 3:07 PM
@Big Chungus Wow! I wish I knew it earlier! Thank you so much 🤗🤗🤗 It's really cool.
b

Big Chungus

12/19/2021, 3:09 PM
Not trying to diminish your work here. Just wanted you to be aware of alternatives out there 😀
n

nilTheDev

12/19/2021, 3:11 PM
Had I known this earlier I wouldn't even have taken the pain to write the script 😅
j

Javier

12/19/2021, 4:18 PM
what is the difference between
kotlinc —script
and just
kotlin
? I just use
kotlin
with no issues to run scripts
b

Big Chungus

12/19/2021, 4:20 PM
kotlinc --script works on all .kts files, kotlin requires .main.kts
👍 4
i

Ignat Beresnev

12/19/2021, 9:57 PM
n

nkiesel

12/20/2021, 9:24 AM
I still think "ki shell" should be called "kshell" for all the Java converts among us...
b

Big Chungus

12/20/2021, 9:47 AM
alias kshell ki
🧌
😂 1
☝️ 1
m

Matteo Mirk

12/22/2021, 10:31 AM
@Big Chungus you have a typo in your first advice, it should be
Copy code
kotlinc -script myFile.kts
with single dash
b

Big Chungus

12/22/2021, 10:33 AM
Ah, yes. Kotlin adopted those shitty java options instead of UNIX...
m

Matteo Mirk

12/22/2021, 10:41 AM
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
3 Views