IMPORTANT FEEDBACK Coming from a javascript and p...
# getting-started
d
IMPORTANT FEEDBACK Coming from a javascript and python background, I am facing great difficulty in using Kotlin. The same for my friends too. For getting good at Kotlin, the environment is kind of like "You must know java or c++ like language if you want to learn Kotlin". Also, I love using the terminal for most of my work. But Kotlin tries to force you to use IntelliJ. I want to mention that I love the language really and I don't want to leave this language behind. But it has been more than a month or two, and I still cannot figure out how to create an executable using Kotlin. And also, I and sick of using IntelliJ. No offense, but using the IDE for a simple program is not worth it. For this, I don't even feel like writing some coding with Kotlin in my daily life. But I am still not leaving it, as I love the language at its core. So, can anyone help me with this? I can be thinking in the wrong way; in which case guide me in the right direction.
👀 1
s
You might find it useful to install the command-line compiler. Once you have that, you can also look at kscript which will let you run simple .kts scripts from the command line. For larger applications, a typical workflow would involve using Gradle as a command line tool to build, run or package the application.
I can definitely understand your frustration; I find that using an IDE feels like a very walled-in experience and doesn’t provide much exposure to the actual command line tools. I’m not sure I’ve ever actually used
kotlinc
directly, despite being a Kotlin programmer for years

r
d
I have used C++ for some time too (not an expert though). But for Kotlin, if I have to learn things in this way by asking people ad trying hard to find out how to do what I am trying to do, I am extremely disappointed...
s
It is strange that even the official docs on Kotlin scripting use IntelliJ so heavily 😕. I would have thought that the whole point of scripting was to shed a lot of that weight
💯 1
d
Not even a single tutorial or documentation exists that does not use IntelliJ for Kotlin. Even for writing a hello world program and creating an executable from it, you need IntelliJ. This is a heartbreaking reality I cannot accept as I am really loving the language.
s
makes mental note to write a blog on how to use Kotlin without IntelliJ
🙏 1
g
You don’t need IntelliJ: Just install gradle and you can create a project with
gradle init
. Then grab your favorite editor and start coding. Personally, I side with @Sam and think that an IDE is a great help even for a small mini-program. About the “executable”: In a JVM-Environment, you don’t create Executables in the sense of a binary that can be called from the shell directly. The nearest to that is a fatJar, meaning a JAR-File that contains every depedency and library. You can then call this with
java -jar <name of jar-file>.jar
.
a
d
@Adam S I have done this.
a
JetBrains is researching how to improve newcomer’s experiences https://kotlinlang.slack.com/archives/C0922A726/p1675353698143759
d
@Goetz Markgraf If I want to create a platform-specific binary. For example, I have created a command program that I want to use for myself in the
.exe
format of Windows. Is it possible with Kotlin?
g
There is kotlin/native that can compile kotlin code to a binary. Or you can use GraalVM to create a binary from a fatJar-File.
s
By default the Gradle application plugin will make you a package that can be started with a Windows
.bat
script. You might need an extra plugin to package that up into an
.exe
but it’s definitely possible
👆 1
a
I think it’s important to keep in mind that Kotlin has multiple targets (JVM, JS, Native, WASM). So some of your questions will depends what the Kotlin target is. Kotlin/Native can produce `.exe`s (although the suffix is
.kexe
on Mac/Linux for some reason). For Kotlin/Native most of the docs don’t use Gradle or IntelliJ, just the command line. https://kotlinlang.org/docs/native-command-line-compiler.html. On Kotlin/JVM, there’s not really a thing as an
.exe
. Java programs just aren’t like that, instead they’re packaged into
.jar
files, and you have to run them using
java -jar test.jar
(There is GraalVM, but that’s quite advanced.)
👍 1
g
@Adam S the
,kexe
ending is only added on linux and macos. On windows its a
.exe
.
🙏 1
For Kotlin/native you have to keep in mind that you can use the Kotlin standard library but not the java library. For example, there is no
File
class in Kotlin/native.
d
Just as an example... Problem: Most of the time, we tend to create/store new random files like images,
.txt
files,
pdf
files on the desktop and soon the desktop becomes a mess. (Windows OS) Goal: I want to write some code to keep my Desktop clean and uncluttered. The program basically detects the files and puts them in the right places and deletes unnecessary files according to the configuration I made in the code. The program runs periodically in the background to do these jobs. So, I need to create a
.exe
and then schedule it as done in Windows. Is, Kotlin the right choice for these things? I love programming and in my spare time, I am always coding something and sharing it with friends. So can Kotlin be used for this kind of general-purpose programming???
đŸ§” 2
g
You can certainly do this with Kotlin. I am not sure if you really have to have an
.exe
-File because the Windows Scheduling can surely also run
.bat
-Files. I recommend using “normal” Kotlin (meaning Kotlin/jvm), what most of documentation is using. You can package your program however you want and create a
.bat
-File to run it.
👍 1
d
one more thing... if I am creating this kind of program in Kotlin, do they use a large portion of system/hardware resources slowing the OS...
l
I don't think it will in your case. It depends on the application, but a periodic job accessing the file system shouldn't need a lot of resources. That being said, a native application typically consumes less resources than a JVM application.
👍 1
g

 but in the native version, @Dron Bhattacharya has to write the file IO functions for himself. Of course, there are examples on the internet for that.
r
Building a Kotlin/JS app with node api and compiling it to an executable with pkg is probably also an interesting option.
k
“This is a heartbreaking reality I cannot accept as I am really loving the language” If you’re going to fight your way against a tide, you’re certainly not going to enjoy swimming in there. Kotlin has been created and evolved by the same company who is very much in the business of writing world-class IDEs. I find it quite straightforward that they would lean on the IDE aspect of it for the tutorials and really the whole experience, no matter how big or small your project is. It’s going to be quite frustrating if you are planning to swim against this tidal current, or if you’re going to be expecting to have the exact same things that you know from other programming environments.
plus1 4
👍 1
c
I’ll also add that different programming languages/environments have different goals, which very much shape the developer experience using that language. Python and JS were both created to be scripting languages, which is why that workflow works very well. But Java (and thereby Kotlin) was created first and foremost for large-scale production applications. The JVM simply was not intended to be a great platform for scripting, so any scripting experience with Java or Kotlin is not going to be as optimized as with other scripting languages. As Kirill said, you’re only going to cause pain for yourself trying to use a tool in a way it’s not optimized for. Yes, Kotlin supports scripting and theoretically can do all the same stuff as Python/JS, but it’s just not optimized for that, and the workflow for creating small utilities like this is not going to be as easy as you might expect given your background. And even outside the Gradle/IntelliJ workflow itself, the language is statically typed, which inherently makes it tricky to use without IDE help, especially if you’re not deeply familiar with the language. But the same thing is true in the other direction. Python/JS are difficult to scale up to huge, enterprise-scale applications because they were optimized for smaller tasks. Again, not that it can’t be done, there great are enterprise-grade frameworks for both those languages like Django or Express, but there’s a reason that Spring and .NET dominate the server-side tech stack. That’s what those languages were optimized for.
👍 1
plus1 3
So my suggestion is this: start with the basic, most widely-used application of a language/framework first before trying to use it for more non-standard ways. For Kotlin, that means sticking with IntelliJ and Gradle targeting the JVM, and only once you’re very familiar with that workflow does it really make sense to start using it for scripting. I understand the frustration of needing to use an IDE for small tasks, especially if you’re on a lower-powered computer, but the frustration of trying to work without it will be even greater.
plus1 6
👍 1
d
When I go through any Kotlin tutorials, I have never come across the concept of
building
I don't know why. But it seems pretty important though. I have done the Kotlin sample project from Gradle Docs.
đŸ§” 4
c
“building” is more-or-less synonymous with “compiling”, and it’s not just a Kotlin term. To “create a build” is to compile the source code, link it with dependencies, and produce an artifact that could be shipped to production and run by the end-users. Kotlin typically uses Gradle as the tool “to build” (verb), which produces “a build” (noun). JS/TS uses WebPack, and uses the same terminology. Same with iOS and XCode (which is both an IDE and the “build tool”). C++ uses Make, etc.
j
d
Currently, I am seeing the Kotlin-docs tools section.
k
Another use of the term "build" is when "building" a String (or a List or other immutable collection), and that's something completely different.