Git Product home page Git Product logo

atomickotlinexamples's Introduction

Atomic Kotlin Examples

If you want to experiment with the code examples from the book Atomic Kotlin, you're in the right place.

These examples are automatically extracted directly from the book. This repository includes tests to verify that the code in the book is correct.

NOTE If you are planning to solve the exercises after reading each atom (and you should), you can get the exercises AND all these examples together by installing the educational course. If you're going to solve the exercises, you can just install the course and you don't need to install the examples from this repository.

Contents

Introduction

The easiest way to access and experiment with the book examples is to clone/download this repository and open it with IntelliJ IDEA. This is all that most people need, and those people can ignore the rest of this README.

The remainder of this README shows you how to build and test the examples using both IntelliJ IDEA and the command line.

Exercises and solutions for the book can be found at AtomicKotlin.com/exercises.

Note: If any terminology or processes described here are still not clear to you, you can usually find explanations or answers through Google. For more specific issues or problems, try StackOverflow. Sometimes you can find installation instructions on YouTube.

Compiling and Running Programs in IntelliJ IDEA

The easiest and fastest way to start using the examples in this book is by compiling and running them using IntelliJ IDEA:

  1. Follow the instructions here to install IntelliJ IDEA.

  2. Download the zipped code repository and unzip it.

  3. Start IntelliJ IDEA and select the File | Open menu item. Navigate to where you unzipped the repository and open the build.gradle file. You should see a dialog box like this:

    Select the Open as Project button.

  4. If you don't see a Project window on the left side, go to the menu and select View | Tool Windows | Project to turn it on.

  5. You'll see an Examples folder. Click on it to open it, then navigate to the HelloWorld folder and open that, then double-click on HelloWorld.kt. You'll see something like this:

    Click on the green triangle in the gutter area to the left of fun main() {. It should look like this:

    Select the top one, the Run option, and IntelliJ IDEA will run your program and display the resulting output.

    NOTE: The first program you run will take awhile, because IntelliJ IDEA is building the entire project. Subsequent programs will start much more quickly.

  6. If you don't already have a JDK (Java Development Kit) on your machine, you will see error messages. A JDK is necessary to compile both Java and Kotlin. You can install one from within IntelliJ. Once the JDK is installed, IDEA will also be able to compile Kotlin.

Building From the Command Line: Quick Version

Before you can run the examples from this repository, you must install the current version of Java, although some earlier versions should also work. (If you get any errors, try upgrading to a more recent version of Java).

If you just want to download and check the code, Download Here and unzip it into your destination directory. Open a shell/command window and move into the root of that directory. You'll know you are in the right directory if you see the files gradlew and gradlew.bat.

You'll need an Internet connection the first time you compile the code, because Gradle needs to first install itself, then all the support libraries. Once these are installed you can perform additional compiling and running offline.

On Mac/Linux, enter:

./gradlew test

(If you get a Permission denied error, run chmod +x ./gradlew)

On Windows, enter

gradlew test

If all goes well, the tests will run. Everything should complete without errors.

All the book examples are in the subdirectory Examples in subdirectories corresponding to the atom names.

To compile and run examples using the Kotlin command-line tools, see Command-Line Hello World.

Building From the Command Line: Detailed Instructions

If you are not familiar with the command line, first read Command-Line Basics.

Install Java

Kotlin runs on top of Java, so you must first install the Java Development Kit (JDK).

Windows

  1. Follow the instructions to install Chocolatey.

  2. At a shell prompt, type: choco install jdk8 (you may also select a more recent version, like jdk11). The installation process takes some time, but when it's finished Java is installed and the necessary environment variables are set.

Macintosh

The Mac comes with a much older version of Java that won't work for the examples in this book, so you'll need to update it to (at least) Java 8.

  1. Follow the instructions at this link to Install HomeBrew

  2. At a shell prompt, first type brew update. When that completes, enter brew cask install java.

NOTE: Sometimes the default version of Java that you get with the above installation will be too recent and not validated by the Mac's security system. If this happens you'll either need to turn off the security by hand or install an earlier version of Java. For either choice, you'll need to Google for answers on how to solve the problem (often the easiest approach is to just search for the error message produced by the Mac).

Linux

Use the standard package installer with the following shell commands:

Ubuntu/Debian:

  1. sudo apt-get update

  2. sudo apt-get install default-jdk

Fedora/Redhat:

su -c "yum install java-1.8.0-openjdk"

Verify Your Installation

Open a new shell and type:

java -version

You should see something like the following (Version numbers and actual text will vary):

openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

If you see a message that the command is not found or not recognized, review the installation instructions. If you still can't get it to work, check StackOverflow.

Installing and Running the Book Examples

Once you have Java installed, the process to install and run the book examples is the same for all platforms:

  1. Download the book examples from the GitHub Repository.

  2. Unzip the downloaded file into the directory of your choice.

  3. Use the Windows Explorer, the Mac Finder, or Nautilus or equivalent on Linux to browse to the directory where you uzipped AtomicKotlinExamples, and open a shell there.

  4. If you're in the right directory, you should see files named gradlew and gradlew.bat in that directory, along with numerous other files and directories. The directories correspond to the chapters in the book.

  5. At the shell prompt, type gradlew test (Windows) or ./gradlew test (Mac/Linux).

The first time you do this, Gradle will install itself and numerous other packages, so it will take some time. After everything is installed, subsequent builds and runs will be much faster.

Note that you must be connected to the Internet the first time you run gradlew so that Gradle can download the necessary packages.

Appendix A: Command-Line Basics

Because it is possible for a "dedicated beginner" to learn programming from this book, you may not have previously used your computer's command-line shell. If you have, you can go directly to the installation instructions.

Editors

To create and modify Kotlin program files—the code listings shown in this book—you need a program called an editor. You'll also need the editor to make changes to your system configuration files, which is sometimes required during installation.

Programming editors vary from heavyweight Integrated Development Environments (IDEs, like Eclipse, NetBeans and IntelliJ IDEA) to more basic text manipulation applications. If you already have an IDE and are comfortable with it, feel free to use that for this book.

Numerous explanations in this book are specific to IntelliJ IDEA so if you don't already have an IDE you might as well start with IDEA. There are many other editors; these are a subculture unto themselves and people sometimes get into heated arguments about their merits. If you find one you like better, it's not too hard to change. The important thing is to choose one and get comfortable with it.

The Shell

If you haven't programmed before, you might be unfamiliar with your operating system shell (also called the command prompt in Windows). The shell harkens back to the early days of computing when everything happened by typing commands and the computer responded by displaying responses—everything was text-based.

Although it can seem primitive in the age of graphical user interfaces, a shell provides a surprising number of valuable features.

To learn more about your shell than we cover here, see Bash Shell for Mac/Linux or Windows Shell.

Starting a Shell

Mac: Click on the Spotlight (the magnifying-glass icon in the upper-right corner of the screen) and type "terminal." Click on the application that looks like a little TV screen (you might also be able to hit "Return"). This starts a shell in your home directory.

Windows: First, start the Windows Explorer to navigate through your directories:

  • Windows 7: click the "Start" button in the lower left corner of the screen. In the Start Menu search box area type "explorer" and then press the "Enter" key.

  • Windows 8: click Windows+Q, type "explorer" and then press the "Enter" key.

  • Windows 10: click Windows+E.

Once the Windows Explorer is running, move through the folders on your computer by double-clicking on them with the mouse. Navigate to the desired folder. Now click the file tab at the top left of the Explorer window and select "Open Windows Powershell." This opens a shell in the destination directory.

Linux: To open a shell in your home directory:

  • Debian: Press Alt+F2. In the dialog that pops up, type 'gnome-terminal'

  • Ubuntu: Either right-click on the desktop and select 'Open Terminal', or press Ctrl+Alt+T

  • Redhat: Right-click on the desktop and select 'Open Terminal'

  • Fedora: Press Alt+F2. In the dialog that pops up, type 'gnome-terminal'

Directories

Directories are one of the fundamental elements of a shell. Directories hold files, as well as other directories. Think of a directory as a tree with branches. If books is a directory on your system and it has two other directories as branches, for example math and art, we say that you have a directory books with two subdirectories math and art. We refer to them as books/math and books/art since books is their parent directory. Note that Windows uses backslashes rather than forward slashes to separate the parts of a directory.

Basic Shell Operations

The shell operations shown here are approximately identical across operating systems. For the purposes of this book, here are the essential operations in a shell:

  • Change directory: Use cd followed by the name of the directory where you want to move, or cd .. if you want to move up a directory. If you want to move to a different directory while remembering where you came from, use pushd followed by the different directory name. Then, to return to the previous directory, just say popd.

  • Directory listing: ls (dir in Windows) displays all the files and subdirectory names in the current directory. Use the wildcard * (asterisk) to narrow your search. For example, if you want to list all the files ending in ".kt," you say ls *.kt (Windows: dir *.kt). If you want to list the files starting with "F" and ending in ".kt," you say ls F*.kt (Windows: dir F*.kt).

  • Create a directory: use the mkdir ("make directory") command (Windows: md), followed by the name of the directory you want to create. For example, mkdir books (Windows: md books).

  • Remove a file: Use rm ("remove") followed by the name of the file you wish to remove (Windows: del). For example, rm somefile.kt (Windows: del somefile.kt).

  • Remove a directory: use the rm -r command to remove the files in the directory and the directory itself (Windows: deltree). For example, rm -r books (Windows: deltree books).

  • Repeat a command: The "up arrow" on all three operating systems moves through previous commands so you can edit and repeat them. On Mac/Linux, !! repeats the last command and !n repeats the nth command.

  • Command history: Use history in Mac/Linux or press the F7 key in Windows. This gives you a list of all the commands you've entered. Mac/Linux provides numbers to refer to when you want to repeat a command.

Unpacking a Zip Archive

A file name ending with .zip is an archive containing other files in a compressed format. Both Linux and Mac have command-line unzip utilities, and it's possible to install a command-line unzip for Windows via the Internet.

However, in all three systems the graphical file browser (Windows Explorer, the Mac Finder, or Nautilus or equivalent on Linux) will browse to the directory containing your zip file. Then right-mouse-click on the file and select "Open" on the Mac, "Extract Here" on Linux, or "Extract all ..." on Windows.

Appendix B: Command-Line Hello World

This appendix explains how to compile and run the program shown in the "Hello World" atom in the book, using the latest version (1.5 or higher) of the Kotlin command-line compiler.

Open up a console window in the HelloWorld directory, where you'll see HelloWorld.kt, and type:

kotlinc HelloWorld.kt

kotlinc means "Kotlin compiler." The compiler is the program that takes your program and turns it into something that will run; this process is called compiling.

Assuming you've typed the code correctly, you should get back the console prompt, with no other messages. If you get error messages, try to discover where you've mis-typed the code, correct it and try again. Once you are successful, you're ready to run the program.

There's one more thing: When you run kotlinc, the resulting program doesn't have the same name as the source program. Instead, the compiler appends a Kt to the name. To see it, run ls or dir on the helloworld subdirectory. You'll see that the directory contains HelloWorldKt.class. What's important is the part before the .class. This is the actual name of the program: HelloWorldKt.

Now we can run the program:

kotlin HelloWorldKt

And you'll see the output on the console:

Hello, world!

Packages

If the program is in a package, the package name is also required to run the program. That is, if Foo.kt contains a package statement:

package bar

then you cannot simply say:

kotlin Foo

You'll get a message starting with error: could not find or load...

If you were to compile this program, you'd see there's a new subdirectory called bar. The name of the subdirectory that appears when you run kotlinc corresponds to the package name in the program that was compiled.

If the program is packaged under bar, we give the package name followed by a "dot," then the program's name:

kotlin bar.FooKt

Appendix C: The Kotlin REPL

The Kotlin interpreter is also called the REPL (for Read-Evaluate-Print- Loop). To use this you must first install the latest version (1.5 or higher) of the Kotlin command-line compiler.

NOTE: You do not need to install command-line Kotlin for the operations described previously in this README.

Install Kotlin

In this book, we use Kotlin version 1.5, the latest available at the time. The detailed installation instructions for the command-line compiler are available at The Kotlin Site.

To check your installation, open a new shell and type:

kotlin -version

at the shell prompt. You'll see the version information for your Kotlin installation.

The REPL

To start the REPL, type kotlinc by itself on the command line. You should see something like the following:

Welcome to Kotlin version 1.5 (JRE 1.8.0_144-b01)
Type :help for help, :quit for quit
>>>

The exact version numbers will vary depending on the versions of Kotlin and Java you've installed, but make sure that you're running Kotlin 1.5 or greater.

The REPL gives you immediate interactive feedback, which is helpful for experimentation. For example, you can do arithmetic:

>>> 42 * 11.3
474.6

Find out more by typing :help at the Kotlin prompt. To exit the REPL, type:

>>> :quit

To compile and run examples using the Kotlin command-line tools, see Command-Line Hello World.

Appendix D: Testing

The test system is built in so that we (the authors) can verify the correctness of what goes into the book.

You don't need to run the tests, but if you want to, you can just run gradlew test (on Windows) or ./gradlew test (Mac/Linux).

There are two steps in creating and running the tests, which you can run separately if you want (again, just running the Gradle test command will validate the code, so you don't need to do the following steps):

  1. gradlew GenerateTests generates tests from the sources in this repository. It creates (or recreates) the file TestExamples.java. You normally don't need to run this; the TestExamples.java in the repository should be up to date.

  2. gradlew TestExamples runs the tests in TestExamples.java.

Alternatively, TestExamples.java can be called as a regular JUnit test class.

atomickotlinexamples's People

Contributors

bruceeckel avatar codybontecou avatar jamesward avatar svtk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

atomickotlinexamples's Issues

1.13 Expressions & Statements, Exercise 2: breakpoints

From the Task Description:

Set breakpoints on lines 4 and 5. [...] Continue the process by clicking on Resume program on the left of the debug window or pressing ⌥⌘R. Notice how the value of the variable x changes after the assignment.

/* 3 */ fun main(args: Array<String>) {
/* 4 */     var x = 1
/* 5 */     x = 2
/* 6 */     println(x)
/* 7 */ }

It seems that if I want to see the value of x change, I should set breakpoints at lines 5 & 6, rather than at 4 & 5... or just put one at 5 and use the 'Step into' button.

When the debugger stops at line 4, that line has not yet executed, so x doesn't exist. When it stops at line 5, only line 4 has executed, so x = 1. Resuming execution with no further breakpoints, we never get to see the value of x change, since the program immediately finishes execution and terminates.

very poor description

All chapter have a very shot descriptions about the subjects and till now I found data class atom the worst and ambiguous in my life.

varandval4, Typo in Task Description

Missing word:

The icons at the top of the Project Tool Window allow (you) to perform several convenient operations.

Also, in IntelliJ 2019.1, I don't seem to have a 'Navigate | Select in...' option in the menu. (screenshot attached)

menu

2.x Introduction to Objects (multiple)

I'm condensing multiple notes for the Introduction to Objects section here. None of these are critical issues.

2.3 Properties, Exercise 1

Task Description

getLocation() should return the coordinates as a string (x, y).

Description appears to want ($x, $y), but unit tests only pass with ($x,$y) (space vs no space)

2.8 Exceptions

// Exceptions/IntroducingNull.kt, Accompanying text:

But what does it mean that the denominator is zero? Maybe you know how to deal with a zero denominator

// Exceptions/AverageIncome.kt, Accompanying text:

Unfortunately, this doesn't tell us anything about why this error occurred, what the denominator means and whether it can legally be zero in the first place.

Phrasing on both suggests that the word 'denominator' has already been seen in an error message, but that is not the case.

2.11 Sets, Exercise 1

To further emphasize DRY, percentOther can also use getPercentage() by passing groceryCart - meats - fruits - vegetables as the first parameter.

2.12 Maps

Exercise 2

Task Description:

It should choose a hamster by a given name, return it and remove it from the list of hamsters.

Solution code doesn't remove the named hamster. It could include the line hamsters -= hamster right before return hamster.

Exercise 3

Same logic, put() puts a hamster in the cage, and take() takes one out, so instead of this:

fun takeHamsterByName(name: String): Hamster =
            hamsters.getValue(name)

We could have this:

fun takeHamsterByName(name: String): Hamster {
        val hamster = hamsters.getValue(name)
        hamsters.remove(name)
        return hamster
    }
Exercise 4, Knowing Your IDE

Just FYI, IntelliJ Column Selection doesn't work with the IdeaVim plugin, but it does work with regular vim commands for the same feature. This is probably too niche to warrant a mention in the book/course, but I thought I'd mention it here anyway.

NPE PlaceholderDependencyManager.getReplacementText and other issues with running examples from Stepic preview

Environment:
IntelliJ IDEA 2018.3 EAP (Ultimate Edition)
Build #IU-183.3283.2, built on October 2, 2018
IntelliJ IDEA EAP User
Expiration date: November 1, 2018
JRE: 1.8.0_152-release-1343-b3 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

Plugin: EduTools v2.0-2018.2-906
Kotlin dependency set ext.kotlin_version = '1.2.51' (as 1.3.0 no yet publically available to gradle-plugin)
Gradle set into 4.7 as 4.10 generate cannot run command-line task with issue (idea.log):

2018-10-08 22:01:02,824 [ 70545] WARN - ecker.gradle.GradleCommandLine - #educational: executing :Programming_Basics-String_Templates-Exercise_2:test fails:

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10/userguide/command_line_interface.html#sec:command_line_warnings

When opening the \AtomicKotlin\Programming Basics\String Templates\Exercise 1\src\Task.kt from either project view or learning view it got exception:

kotlin.KotlinNullPointerException
at com.jetbrains.edu.learning.placeholderDependencies.PlaceholderDependencyManager.getReplacementText(PlaceholderDependencyManager.kt:81)
at com.jetbrains.edu.learning.placeholderDependencies.PlaceholderDependencyManager.updateDependentPlaceholders(PlaceholderDependencyManager.kt:51)
at com.jetbrains.edu.learning.editor.EduEditorFactoryListener.editorCreated(EduEditorFactoryListener.java:102)
at sun.reflect.GeneratedMethodAccessor335.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.util.EventDispatcher.dispatchVoidMethod(EventDispatcher.java:133)
at com.intellij.util.EventDispatcher.access$100(EventDispatcher.java:25)
at com.intellij.util.EventDispatcher$3.invoke(EventDispatcher.java:96)
at com.sun.proxy.$Proxy43.editorCreated(Unknown Source)
at com.intellij.openapi.editor.impl.EditorFactoryImpl.createEditor(EditorFactoryImpl.java:208)
at com.intellij.openapi.editor.impl.EditorFactoryImpl.createEditor(EditorFactoryImpl.java:160)
at com.intellij.openapi.fileEditor.impl.text.TextEditorComponent.createEditor(TextEditorComponent.java:144)
at com.intellij.openapi.fileEditor.impl.text.TextEditorComponent.(TextEditorComponent.java:81)
at com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorImpl$PsiAwareTextEditorComponent.(PsiAwareTextEditorImpl.java:96)
at com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorImpl$PsiAwareTextEditorComponent.(PsiAwareTextEditorImpl.java:89)
at com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorImpl.createEditorComponent(PsiAwareTextEditorImpl.java:74)
at com.intellij.openapi.fileEditor.impl.text.TextEditorImpl.(TextEditorImpl.java:56)
at com.intellij.openapi.fileEditor.impl.text.PsiAwareTextEditorImpl.(PsiAwareTextEditorImpl.java:45)
at com.jetbrains.edu.learning.editor.EduEditor.(EduEditor.java:27)
at com.jetbrains.edu.learning.editor.EduFileEditorProvider.createEditor(EduFileEditorProvider.java:29)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.lambda$openFileImpl4$8(FileEditorManagerImpl.java:858)
at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:672)
at com.intellij.openapi.application.impl.ApplicationImpl.invokeAndWait(ApplicationImpl.java:685)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl4(FileEditorManagerImpl.java:963)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl3(FileEditorManagerImpl.java:783)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.lambda$openFileImpl2$4(FileEditorManagerImpl.java:765)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:212)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:178)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:168)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:154)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileImpl2(FileEditorManagerImpl.java:765)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openFileWithProviders(FileEditorManagerImpl.java:696)
at com.intellij.openapi.fileEditor.ex.FileEditorManagerEx.openFile(FileEditorManagerEx.java:145)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.lambda$openEditor$10(FileEditorManagerImpl.java:1121)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:212)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:178)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:168)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:154)
at com.intellij.openapi.fileEditor.impl.FileEditorManagerImpl.openEditor(FileEditorManagerImpl.java:1119)
at com.intellij.openapi.fileEditor.OpenFileDescriptor.navigateInAnyFileEditor(OpenFileDescriptor.java:152)
at com.intellij.openapi.fileEditor.OpenFileDescriptor.navigateInEditor(OpenFileDescriptor.java:138)
at com.intellij.openapi.fileEditor.OpenFileDescriptor.navigateInEditorOrNativeApp(OpenFileDescriptor.java:134)
at com.intellij.openapi.fileEditor.OpenFileDescriptor.navigate(OpenFileDescriptor.java:117)
at com.intellij.psi.impl.source.PsiFileImpl.navigate(PsiFileImpl.java:892)
at com.intellij.codeInsight.navigation.NavigationUtil.lambda$openFileWithPsiElement$1(NavigationUtil.java:176)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:220)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:178)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:168)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:154)
at com.intellij.codeInsight.navigation.NavigationUtil.openFileWithPsiElement(NavigationUtil.java:169)
at com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode.navigate(AbstractPsiBasedNode.java:228)
at com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode.navigate(AbstractPsiBasedNode.java:238)
at com.intellij.ide.projectView.impl.nodes.PsiFileNode.navigate(PsiFileNode.java:133)
at com.intellij.util.OpenSourceUtil.navigateToSource(OpenSourceUtil.java:119)
at com.intellij.util.OpenSourceUtil.navigate(OpenSourceUtil.java:74)
at com.intellij.util.OpenSourceUtil.navigate(OpenSourceUtil.java:58)
at com.intellij.util.OpenSourceUtil.navigate(OpenSourceUtil.java:51)
at com.intellij.util.OpenSourceUtil.openSourcesFrom(OpenSourceUtil.java:19)
at com.intellij.util.EditSourceOnDoubleClickHandler$TreeMouseListener.processDoubleClick(EditSourceOnDoubleClickHandler.java:128)
at com.intellij.util.EditSourceOnDoubleClickHandler$TreeMouseListener.onDoubleClick(EditSourceOnDoubleClickHandler.java:120)
at com.intellij.ui.DoubleClickListener.onClick(DoubleClickListener.java:30)
at com.intellij.ui.ClickListener$1.mouseReleased(ClickListener.java:73)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
at java.awt.Component.processMouseEvent(Component.java:6548)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3325)
at com.intellij.ui.treeStructure.Tree.processMouseEvent(Tree.java:410)
at com.intellij.ide.dnd.aware.DnDAwareTree.processMouseEvent(DnDAwareTree.java:58)
at java.awt.Component.processEvent(Component.java:6313)
at java.awt.Container.processEvent(Container.java:2237)
at java.awt.Component.dispatchEventImpl(Component.java:4903)
at java.awt.Container.dispatchEventImpl(Container.java:2295)
at java.awt.Component.dispatchEvent(Component.java:4725)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4889)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4526)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4467)
at java.awt.Container.dispatchEventImpl(Container.java:2281)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4725)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764)
at java.awt.EventQueue.access$500(EventQueue.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:715)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:737)
at java.awt.EventQueue$4.run(EventQueue.java:735)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:719)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:664)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:363)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

@svtk

The hint button no longer works

Hi! The hint button used to work fine a few days ago and now clicking it doesn't do anything. It's driving me a little nuts, to the point of completely uninstalling IntelliJ IDEA (and any files) and re-installing everything including the course but it still doesn't do anything.

It's just sitting there... begging to be clicked. But once clicked, it does nothing. It just disappoints :(
https://i.imgur.com/C2gfZn5.png

Book not available for purchase via Stepik

When trying to buy the full version of the book via Stepik, it says "You cannot buy this course yet."

After I've finished the free sample ("Programming Basics" and "Introduction to Objects") yesterday and tried to buy the full content of the Stepik version, sadly it wasn't possible anymore, with the information "You cannot buy this course yet." on all views where a purchase was normally possible.

[book] Type Inference (type rules) algorithm

From the book at Number Types

The location where the L appears is unimportant. If one of the values is Long, the resulting expression is Long.

Not true, there is an actual result in case I move L val to the different place:

fun main() {
  val i = Int.MAX_VALUE
  println(i + i + 0L)  // overflow, because of math rule
}

type-rule

Anyway, can you explain Type Inference (type rules) algo or point me to an authoritative resource?

i have trouble in running helloworld.kt , help me ?

i read your book atomic kotlin,
but i have trouble in running "helloworld.kt"

i run helloworld.kt at macbook pro m2 pro, macos ventura 13.3, IntelliJ idea community edition 2023.1
i installed intellij with jetbrain toolbox.

image

how can i fix this trouble ?

i can't start a page with this book.

please help me

1.14 Summary 1, Exercise 4: pad width

From the Task Description:

For proper alignment use "%3d".format(number) to place additional spaces before the number.

With that phrasing I would expect to use the provided expression nearly verbatim. However, exercise code doesn't pass the 2x2 unit test or match the expected 3x3 output in the description without calculating width with (rows * columns).toString().length + 1 and then using "%${width}d".format(number), rather than just hard-coding it to 3.

This is apparent after a 'Peek Solution...', but I think a learner would have a better shot at writing passing code on their own if at least one of the following were provided:

  • A previous exercise illustrating how to combine string templates and format strings
  • A more detailed response if the 2x2 unit test fails
  • Phrasing changed to:

For proper alignment use a format string such as "%3d".format(number) to place additional spaces before the number.

  • A call to printSnake(3, 3) added to main() to give that use case better visibility, and expected output added to the commented output alongside the expected 4x5 output:
fun main(args: Array<String>) {
    printSnake(4, 5)
    println()
    printSnake(3, 3)
}
/* Output:
  0  1  2  3  4
  9  8  7  6  5
 10 11 12 13 14
 19 18 17 16 15

 0 1 2
 5 4 3
 6 7 8
*/

If people who are completely new to programming are among the target audience, this might also be a nice place to explicitly mention the pitfalls of hard-coding values. After all, it isn't immediately apparent that output of a small table with width hard-coded to 3 is 'wrong', especially if you look at a 2x5 next to the 4x5:

/* Output:
  0  1  2  3  4
  9  8  7  6  5
 10 11 12 13 14
 19 18 17 16 15

  0  1  2  3  4
  9  8  7  6  5
*/

An alignment mismatch between cells wouldn't manifest until creating a table with over 1000 cells, and that could be considered outside intended use since it would also overflow a standard 80x24 terminal.

Note also that (row, column) means parameters are in (y, x) order, inverse to the more conventional (x, y).

I'm not trying to be annoying, I promise. I'm trying to be helpful since the book is still in beta. Feel free to disregard any or all of the issues I've opened, because they're all minor and subjective.

A slightly confusing reference to an atom.

Hi, first of all thanks for the book.

I was reading the "Looping and Ranges" section and realised that something may be missing.

After you show the // LoopingAndRanges/HasChar.kt atom, you say:

The next atom shows that hasChar() is unnecessary—you can use built-in syntax
instead.

But after that text, there is no atom and it follows:

If you simply want to repeat an action a fixed number of times, you may use
repeat() instead of a for loop

And then the // LoopingAndRanges/RepeatHi.kt atom.

I tried to look for the code in the repository but I can't find it. I don't know if that atom is missing or that bit of text is left over.

Best regards.

Incompatible with current Gradle version

Hi there, I'm trying to run the course in the version of IntelliJ IDEA CE that I just installed (v. 2023.2.1). My Gradle configuration is whatever is default for that version. I have followed all the troubleshooting steps and the problem has not resolved. When I go to check any of the exercises I get the following output:

Problem configuring task :wrapper from command line.
> Unknown command-line option '--tests'.

* Try:
> Run gradle help --task :wrapper to get task usage details.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.2/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 2s

I'm very frustrated and not sure how to proceed. I mainly bought this book for the IntelliJ integration.

Thanks for your help!

Selectively disable linting, if possible

It would be nice if the AtomicKotlin course could temporarily disable IntelliJ linting in some places. For example, in "var & val" Exercise 1, the "correct" code is:

    var answer = 42
    answer = 43

...and the linter complains that "Variable 'answer' initializer is redundant." IntelliJ isn't wrong, but it detracts from the clarity of the lesson.

Typo

There's a typo on page 253 in the first paragraph. The phrase "while expression" should read "when expression". Fantastic book by the way!! Thank you so much for spending the time and making this amazing resource available.

outdated

the course is outdated as hell on jetbrains idea

1.14 Summary 1, Exercise 2: minor efficiency boost

while loop given in solution:

    while (worker > 0) {
        result += worker % 10
        worker /= 10
        if (worker != 0) {
            result *= 10
        }
    }

The check performed inside the if is effectively identical to the check performed in the while loop, so this can be simplified:

    while (worker > 0) {
        result *= 10
        result += worker % 10
        worker /= 10
    }

The first iteration of result *= 10 performs no unwanted action since at that point result is still initialized to zero.

String index

Chapter 1, Repetition with while, Exrcise1
it asks for printing each character in the string while you didn't teach how to work with index at all before

1.9 Booleans, open/closed logic

If a business closes at hour 20, and the current hour is 20, the business is closed.

In the following line from Booleans2.kt, the second Boolean test should be <, not <=.
val isOpen = hour >= open && hour <= closed

Likewise, in the following line from Booleans3.kt, the second Boolean test should be >=, not just >.
val isClosed = hour < open || hour > closed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.