Learning Kotlin: Programming with Visual Studio Code
Tags: kotlin, programming, todayilearned
Published: 2021-04-20 05:47:53

<p>Kotlin has been a pretty steadily growing programming language over the last few years and yet I have never gotten a chance to use the language. Most of the work I do is in c# which doesn’t seem to be that different from Kotlin so I’m interested to see how long it will take me to get familiar with the language. I figured I would document how I go about getting&nbsp;started!</p><h3><strong>The IDE</strong></h3><p>For those following along, there is<a href="https://kotlinlang.org/docs/jvm-get-started.html"> official documentation</a> that seems to be fairly straightforward. Maybe the IntelliJ IDEA is amazing, but I honestly hate having to download a full IDE just to try out a language. So instead of following that, I’m going to be using <a href="https://code.visualstudio.com/">Visual studio&nbsp;code</a>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Sn6S8prmMYzTkgTh"><figcaption>Source: <a href="https://code.visualstudio.com/assets/home/home-screenshot-mac-2x.png">Visual&nbsp;Studio</a></figcaption></figure><p>To get started, you are going to need to install the compiler. To do this, go ahead and run the following commands via the command line via <a href="https://brew.sh/">Homebrew</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_omtbOYNuIBrYpec"></figure><h3>VS Extensions</h3><p>In order to support programming languages in VS Code, you are going to need to install an extension from the <a href="https://marketplace.visualstudio.com/vscode">Visual Studio Marketplace</a>. The extension that we need to download is called “Kotlin Language” by Mathias Fröhlich. See this screenshot below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pMs2r_srYyp-Vf1b"></figure><p>If you don’t already, Code Runner is another extension that you will need to have in order to execute Kotlin code in VS Code. Using the same process as before, look for “Code Runner” in the extension store. This extension is really useful for being able to execute a bunch of different code&nbsp;source.</p><blockquote>“Run code snippet or code file for multiple languages: <strong>C, C++, Java, JavaScript, PHP, Python, Perl, Perl 6, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F# Script, F# (.NET Core), C# Script, C# (.NET Core), VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml Script, R, AppleScript, Elixir, Visual Basic&nbsp;.NET, Clojure, Haxe, Objective-C, Rust, Racket, Scheme, AutoHotkey, AutoIt, Kotlin, Dart, Free Pascal, Haskell, Nim, D, Lisp, Kit, V, SCSS, Sass, CUDA, Less, Fortran</strong>, and custom&nbsp;command”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QiQIPFnHVpqx9vdg"></figure><p>Once you have everything downloaded, create a new file called <em>“hello.kt”</em> and add the following lines:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tiKLBr6wqCRmz8Cw"></figure><p>Upon saving the file, right click and select: “Run&nbsp;Code”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/0*RkJSkEocmgz_DV33"></figure><p>After compiling, you should see an output window appear. Here’s what mine looked&nbsp;like!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*g1CzcikM4XiJBOGl"></figure><p>Congratulations, you’ve just run your first Kotlin code! Next post, we’ll get into the fun stuff but for now, we have everything ready to go&nbsp;😎</p><p><strong>Thank you for reading this far. If you enjoyed this post, please share, comment, and press that 👏&nbsp;!</strong></p><p><strong>Follow me on </strong><a href="https://twitter.com/maurerpwer"><strong>Twitter</strong></a><strong> and Medium if you’re interested in more in-depth and informative write-ups like these in the&nbsp;future!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&amp;referrerSource=full_rss&amp;postId=a69e4daa0348" width="1" height="1" alt=""></div>