Programming Kotlin Applications. Бретт Мак-Лахлин

Programming Kotlin Applications - Бретт Мак-Лахлин


Скачать книгу
need advanced permissions to install the Launcher Script that IntelliJ creates if you accepted the default location on Mac OS X.

Snapshot of IntelliJ makes getting going in Kotlin simple and prompts you on creating a new project to include Kotlin libraries.

      Create Your Kotlin Program

      NOTE Your IDE may not be configured exactly like mine. If you don't see the src/ folder, you may need to click Project on the left side of your IDE to display the various folders, and possibly click again on the name of the project.

Snapshot of Kotlin code should go in the src/ folder.

      NOTE From this point forward, code will typically not be shown in an IDE. That way, you can use the IDE of your choice (or the command line), because you should get the same results across IDEs.

Snapshot of IntelliJ automatically formats code and adds sensible syntax highlighting.

      Compile and Run Your Kotlin Program

Snapshot of the empty output of your program displaying in its own window.

      In this case, you shouldn't get any errors, but there's not any output either. We'll fix that shortly.

      Fix Any Errors as They Appear

      You can then easily fix the error and rebuild.

      Install Kotlin (and Use the Command Line)

      For power users, there's a tendency to want to use the command line for nearly everything. Kotlin is no exception. Because it's “mostly Java” in the sense that it runs using a JVM and JDK, you can get pretty far without a lot of work.

      Command-Line Kotlin on Windows

      For Windows users, you'll first need a JDK. You can download one from the Oracle Java download page at www.oracle.com/technetwork/java/javase/downloads. That download has version-specific instructions that are easy to follow.

Snapshot of Good IDEs helping you quickly find and fix errors.

      NOTE These instructions are intentionally a bit sparse. If you're using the command line already, you probably don't need a lot of hand holding. For almost everyone else, though, using an IDE really is the best approach. As a bonus, you can also use IntelliJ as a proxy for the compiler, so you may just want to save the time it would take you to mess with the command line and put it into coding Kotlin!

      Command-Line Kotlin on Mac OS X

      The easiest path to getting Kotlin working on Mac OS X is to use one of the package managers popular on Macs: either Homebrew (brew.sh) or MacPorts (www.macports.org). Both of these make getting Kotlin up and running trivial.

      For MacPorts, just run the following command:

      brett $ sudo port install kotlin

      This requires elevated permissions, but after it runs, you'll be all set.

      For Homebrew, first do an update:

      brett $ brew update

      Next up, install Kotlin:


Скачать книгу