Skip to content

Commit 9de6765

Browse files
LiYing2010koshachy
andauthored
minor fix for typo, indent, link, and sample code (JetBrains#3179)
* minor fix for typo, indent, link, and sample code * chore: rollback the wrong article * chore: new line added * chore: fix indents * chore: add bells and whistles * Update kotlin-tips.md * fix sample code, remove versions which have duplicated content, keep only 1 version Co-authored-by: Andrey Polyakov <koshachy@gmail.com>
1 parent 333395b commit 9de6765

30 files changed

+193
-206
lines changed

docs/topics/coding-conventions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ a type alias for it:
879879
typealias MouseClickHandler = (Any, MouseEvent) -> Unit
880880
typealias PersonIndex = Map<String, Person>
881881
```
882-
If you use a private or internal type alias for avoiding name collision, prefer the `import as ` mentioned in
882+
If you use a private or internal type alias for avoiding name collision, prefer the `import ... as ...` mentioned in
883883
[Packages and Imports](packages.md).
884884

885885
### Lambda parameters

docs/topics/competitive-programming.md

+14-30
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ features as [tail recursion](functions.md#tail-recursive-functions):
4141
```kotlin
4242
tailrec fun removeZeroes(x: Int): Int =
4343
if (x % 10 == 0) removeZeroes(x / 10) else x
44-
44+
4545
fun f(x: Int) = removeZeroes(x + 1)
4646
```
4747

@@ -80,7 +80,6 @@ fun main() {
8080
while (reached.add(n)) n = f(n) // iterate function f
8181
println(reached.size) // print answer to the output
8282
}
83-
8483
```
8584

8685
There is no need to handle the case of misformatted input in competitive programming. An input format is always precisely
@@ -127,17 +126,17 @@ the following helper functions for reading inputs in competitive programming:
127126
<tab title="Kotlin 1.6.0 and later" group-key="kotlin-1-6">
128127

129128
```kotlin
130-
private fun readInt() = readln().toInt()
131-
private fun readStr() = readln().toString()
129+
private fun readStr() = readln() // string line
130+
private fun readInt() = readStr().toInt() // single int
132131
// similar for other types you'd use in your solutions
133132
```
134133

135134
</tab>
136135
<tab title="Earlier versions" group-key="kotlin-1-5">
137136

138137
```kotlin
139-
private fun readInt() = readLn().toInt()
140-
private fun readStr() = readLn().toString()
138+
private fun readStr() = readLine()!! // string line
139+
private fun readInt() = readStr().toInt() // single int
141140
// similar for other types you'd use in your solutions
142141
```
143142

@@ -224,18 +223,20 @@ you can have the following list of helper input-reading functions:
224223
<tab title="Kotlin 1.6.0 and later" group-key="kotlin-1-6">
225224

226225
```kotlin
227-
private fun readInt() = readln().toInt() // single int
228-
private fun readStrings() = readln().split(" ") // list of strings
226+
private fun readStr() = readln() // string line
227+
private fun readInt() = readStr().toInt() // single int
228+
private fun readStrings() = readStr().split(" ") // list of strings
229229
private fun readInts() = readStrings().map { it.toInt() } // list of ints
230230
```
231231

232232
</tab>
233233
<tab title="Earlier versions" group-key="kotlin-1-5">
234234

235235
```kotlin
236-
private fun readLn() = readLine()!! // string line
237-
private fun readInt() = readLn().toInt() // single int
238-
private fun readStrings() = readLn().split(" ") // list of strings
236+
private fun readStr() = readLine()!! // string line
237+
private fun readInt() = readStr().toInt() // single int
238+
private fun readStrings() = readStr().split(" ") // list of strings
239+
private fun readInts() = readStrings().map { it.toInt() } // list of ints
239240
```
240241

241242
</tab>
@@ -244,29 +245,13 @@ private fun readStrings() = readLn().split(" ") // list of strings
244245
With these helpers, the part of code for reading input becomes simpler, closely following the input
245246
specification in the problem statement line by line:
246247

247-
<tabs group="kotlin-versions">
248-
<tab title="Kotlin 1.6.0 and later" group-key="kotlin-1-6">
249-
250248
```kotlin
251249
// read input
252250
val n = readInt()
253-
val s = readln()
251+
val s = readStr()
254252
val fl = readInts()
255253
```
256254

257-
</tab>
258-
<tab title="Earlier versions" group-key="kotlin-1-5">
259-
260-
```kotlin
261-
// read input
262-
val n = readInt()
263-
val s = readLn()
264-
val fl = readInts()
265-
```
266-
267-
</tab>
268-
</tabs>
269-
270255
Note that in competitive programming it is customary to give variables shorter names than it is
271256
typical in industrial programming practice, since the code is to be written just once and not supported thereafter.
272257
However, these names are usually still mnemonic — `a` for arrays,
@@ -286,7 +271,7 @@ In Kotlin this line can be concisely parsed with the following statement using
286271
from a list of integers:
287272

288273
```kotlin
289-
val (n, k) = readInts()
274+
val (n, k) = readInts()
290275
```
291276

292277
It might be temping to use JVM's `java.util.Scanner` class to parse less structured
@@ -323,4 +308,3 @@ is not perfect, and it is still worth familiarizing yourself with Kotlin and lea
323308

324309
A great resource to study Kotlin syntax and API of the Kotlin standard library are
325310
[Kotlin Koans](koans.md).
326-

docs/topics/components-stability.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Each Kotlin project has two GitHub badges describing its stability and support s
4444
* ![Beta stability level](https://kotl.in/badges/beta.svg){type="joined"} stands for **Beta**
4545
* ![Stable stability level](https://kotl.in/badges/stable.svg){type="joined"} stands for **Stable**
4646

47-
* **Support** status. This shows our commitment to maintaining a project and helping users to solve their problems
47+
* **Support** status. This shows our commitment to maintaining a project and helping users to solve their problems.
4848
The level of support is unified for all JetBrains products.
4949
[See the JetBrains Confluence document for details](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub).
5050

docs/topics/configure-build-for-eap.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ plugins {
4141
}
4242

4343
repositories {
44-
mavenCentral()
44+
mavenCentral()
4545
}
4646
```
4747

@@ -144,4 +144,4 @@ In the sample Maven project definition, replace `KOTLIN-EAP-VERSION` with the ac
144144
</plugins>
145145
</build>
146146
</project>
147-
```
147+
```

docs/topics/gradle.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ require the `kotlin-multiplatform` plugin. [Learn more about the plugin](multipl
6161

6262
```kotlin
6363
plugins {
64-
kotlin("multiplatform") version "%kotlinVersion%"
64+
kotlin("multiplatform") version "%kotlinVersion%"
6565
}
6666
```
6767

@@ -70,7 +70,7 @@ plugins {
7070

7171
```groovy
7272
plugins {
73-
id 'org.jetbrains.kotlin.multiplatform' version '%kotlinVersion%'
73+
id 'org.jetbrains.kotlin.multiplatform' version '%kotlinVersion%'
7474
}
7575
```
7676

@@ -82,7 +82,7 @@ plugins {
8282
To target the JVM, apply the Kotlin JVM plugin.
8383

8484
<tabs group="build-script">
85-
<tab title="Kotlin" group-key="kotlin">
85+
<tab title="Kotlin" group-key="kotlin">
8686

8787
```kotlin
8888
plugins {
@@ -116,7 +116,7 @@ Applying Kotlin plugins with `apply` in the Kotlin Gradle DSL is not recommended
116116

117117
Kotlin sources and Java sources can be stored in the same folder, or they can be placed in different folders. The default convention is to use different folders:
118118

119-
```groovy
119+
```text
120120
project
121121
- src
122122
- main (root)
@@ -479,7 +479,7 @@ plugin won't override it or add a second standard library.
479479

480480
If you do not need a standard library at all, you can add the opt-out option to the `gradle.properties`:
481481

482-
```kotlin
482+
```properties
483483
kotlin.stdlib.default.dependency=false
484484
```
485485

@@ -1088,18 +1088,18 @@ You can specify arguments for a specific task:
10881088
```kotlin
10891089
tasks.withType<CompileUsingKotlinDaemon>().configureEach {
10901090
kotlinDaemonJvmArguments.set(listOf("-Xmx486m", "-Xms256m", "-XX:+UseParallelGC"))
1091-
}
1091+
}
10921092
```
1093-
1093+
10941094
</tab>
10951095
<tab title="Groovy" group-key="groovy">
10961096

10971097
```groovy
10981098
tasks.withType(CompileUsingKotlinDaemon::class).configureEach { task ->
10991099
task.kotlinDaemonJvmArguments.set(["-Xmx1g", "-Xms512m"])
1100-
}
1100+
}
11011101
```
1102-
1102+
11031103
</tab>
11041104
</tabs>
11051105

@@ -1158,7 +1158,7 @@ The available values for the `compilerExecutionStrategy` task property are:
11581158
2. `org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy.IN_PROCESS`
11591159
3. `org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy.OUT_OF_PROCESS`
11601160

1161-
Use the task property `compilerExecutionStrategy` in your buildscripts:
1161+
Use the task property `compilerExecutionStrategy` in your build scripts:
11621162

11631163
<tabs group="build-script">
11641164
<tab title="Kotlin" group-key="kotlin">
@@ -1185,7 +1185,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy
11851185
11861186
tasks.withType(KotlinCompile)
11871187
.configureEach {
1188-
compilerExecutionStrategy.set(KotlinCompilerExecutionStrategy.IN_PROCESS)
1188+
compilerExecutionStrategy.set(KotlinCompilerExecutionStrategy.IN_PROCESS)
11891189
}
11901190
```
11911191

docs/topics/js/js-project-setup.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ To run tests, execute the standard lifecycle `check` task:
323323
./gradlew check
324324
```
325325
326-
To specify envirnoment variables used by your Node.js test runners (for example, to pass external information to your tests, or to fine-tune package resolution), use the `environment` function with a key-value pair inside the `testTask` block in your build script:
326+
To specify environment variables used by your Node.js test runners (for example, to pass external information to your tests, or to fine-tune package resolution), use the `environment` function with a key-value pair inside the `testTask` block in your build script:
327327

328328
```groovy
329329
kotlin {

docs/topics/jvm/java-to-kotlin-collections-guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ In Java, there are mutable collections:
109109
```java
110110
// Java
111111
// This list is mutable!
112-
public List<Customer> getCustomers() { }
112+
public List<Customer> getCustomers() { ... }
113113
```
114114
{id="mutability-java"}
115115

docs/topics/kapt.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask>()
142142
```groovy
143143
tasks.withType(org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask.class)
144144
.configureEach {
145-
kaptProcessJvmArgs.add('-Xmx512m')
145+
kaptProcessJvmArgs.add('-Xmx512m')
146146
}
147147
```
148148

@@ -182,7 +182,7 @@ kapt.classloaders.cache.disableForProcessors=[annotation processors full names]
182182
Get a performance statistics on the annotation processors execution using the `-Kapt-show-processor-timings` plugin option.
183183
An example output:
184184

185-
```kotlin
185+
```text
186186
Kapt Annotation Processing performance report:
187187
com.example.processor.TestingProcessor: total: 133 ms, init: 36 ms, 2 round(s): 97 ms, 0 ms
188188
com.example.processor.AnotherProcessor: total: 100 ms, init: 6 ms, 1 round(s): 93 ms
@@ -191,7 +191,7 @@ com.example.processor.AnotherProcessor: total: 100 ms, init: 6 ms, 1 round(s): 9
191191
You can dump this report into a file with the plugin option [`-Kapt-dump-processor-timings` (`org.jetbrains.kotlin.kapt3:dumpProcessorTimings`)](https://github.com/JetBrains/kotlin/pull/4280).
192192
The following command will run kapt and dump the statistics to the `ap-perf-report.file` file:
193193

194-
```kotlin
194+
```bash
195195
kotlinc -cp $MY_CLASSPATH \
196196
-Xplugin=kotlin-annotation-processing-SNAPSHOT.jar -P \
197197
plugin:org.jetbrains.kotlin.kapt3:aptMode=stubsAndApt,\
@@ -233,7 +233,7 @@ The statistics will appear in the logs with the `info` level. You'll see the `An
233233
statistics on the execution time of each annotation processor. After these lines, there will be the `Generated files report:` line
234234
followed by statistics on the number of generated files for each annotation processor. For example:
235235

236-
```kotlin
236+
```text
237237
[INFO] Annotation processor stats:
238238
[INFO] org.mapstruct.ap.MappingProcessor: total: 290 ms, init: 1 ms, 3 round(s): 289 ms, 0 ms, 0 ms
239239
[INFO] Generated files report:
@@ -257,7 +257,7 @@ To run kapt with compile avoidance:
257257
* Add the annotation processor dependencies to the `kapt*` configurations manually as described [above](#using-in-gradle).
258258
* Turn off the discovery of annotation processors in the compile classpath by adding this line to your `gradle.properties` file:
259259

260-
```
260+
```properties
261261
kapt.include.compile.classpath=false
262262
```
263263

@@ -268,7 +268,7 @@ Currently, annotation processing can be incremental only if all annotation proce
268268

269269
To disable incremental annotation processing, add this line to your `gradle.properties` file:
270270

271-
```
271+
```properties
272272
kapt.incremental.apt=false
273273
```
274274

docs/topics/kotlin-tips.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,55 @@ Kotlin Tips is a series of short videos where members of the Kotlin team show ho
66

77
## null + null in Kotlin
88

9-
What happens when you add `null + null` in Kotlin, and what does it return? Sebastian addresses this mystery in our latest quick tip. Along the way, he also shows why there's no reason to be scared of nullables:
9+
What happens when you add `null + null` in Kotlin, and what does it return? Sebastian Aigner addresses this mystery in our latest quick tip. Along the way, he also shows why there's no reason to be scared of nullables:
1010

1111
<video width="560" height="315" href="wwplVknTza4" title="Kotlin Tips: null + null in Kotlin"/>
1212

1313
## Deduplicating collection items
1414

15-
Got a Kotlin collection that contains duplicates? Need a collection with only unique items? Let Sebastian show you how to remove duplicates from your lists, or turn them into sets in this Kotlin tip:
15+
Got a Kotlin collection that contains duplicates? Need a collection with only unique items? Let Sebastian Aigner show you how to remove duplicates from your lists, or turn them into sets in this Kotlin tip:
1616

1717
<video width="560" height="315" href="ECOf0PeSANw" title="Kotlin Tips: Deduplicating Collection Items"/>
1818

1919
## The suspend and inline mystery
2020

21-
How come functions like [`repeat()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/repeat.html), [`map()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/map.html) and [`filter()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/filter.html) accept suspending functions in their lambdas, even though their signatures aren't coroutines-aware? In this episode of Kotlin Tips Sebastian solves the riddle: it has something to do with the inline modifier:
21+
How come functions like [`repeat()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/repeat.html), [`map()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/map.html) and [`filter()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/filter.html) accept suspending functions in their lambdas, even though their signatures aren't coroutines-aware? In this episode of Kotlin Tips Sebastian Aigner solves the riddle: it has something to do with the inline modifier:
2222

2323
<video width="560" height="315" href="R2395u7SdcI" title="Kotlin Tips: The Suspend and Inline Mystery"/>
2424

2525
## Unshadowing declarations with their fully qualified name
2626

27-
Shadowing means having two declarations in a scope have the same name. So, how do you pick? In this episode of Kotlin Tips Sebastian shows you a simple Kotlin trick to call exactly the function that you need, using the power of fully qualified names:
27+
Shadowing means having two declarations in a scope have the same name. So, how do you pick? In this episode of Kotlin Tips Sebastian Aigner shows you a simple Kotlin trick to call exactly the function that you need, using the power of fully qualified names:
2828

2929
<video width="560" height="315" href="mJRzF9WtCpU" title="Kotlin Tips: Unshadowing Declarations"/>
3030

3131
## Return and throw with the Elvis operator
3232

33-
[Elvis](null-safety.md#elvis-operator) has entered the building once more! Seb explains why the operator is named after the famous singer, and how you can use `?:` in Kotlin to return or throw. The magic behind the scenes? [The Nothing type](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-nothing.html).
33+
[Elvis](null-safety.md#elvis-operator) has entered the building once more! Sebastian Aigner explains why the operator is named after the famous singer, and how you can use `?:` in Kotlin to return or throw. The magic behind the scenes? [The Nothing type](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-nothing.html).
3434

3535
<video width="560" height="315" href="L8aFK7QrbA8" title="Kotlin Tips: Return and Throw with the Elvis Operator"/>
3636

3737
## Destructuring declarations
3838

39-
With [destructuring declarations](destructuring-declarations.md) in Kotlin, you can create multiple variables from a single object, all at once. In this video Sebastian shows you a selection of things that can be destructured – pairs, lists, maps, and more. And what about your own objects? Kotlin's component functions provide an answer for those as well:
39+
With [destructuring declarations](destructuring-declarations.md) in Kotlin, you can create multiple variables from a single object, all at once. In this video Sebastian Aigner shows you a selection of things that can be destructured – pairs, lists, maps, and more. And what about your own objects? Kotlin's component functions provide an answer for those as well:
4040

4141
<video width="560" height="315" href="zu1PUAvk_Lw" title="Kotlin Tips: Destructuring Declarations"/>
4242

4343
## Operator functions with nullable values
4444

45-
In Kotlin, you can override operators like addition and subtraction for your classes and supply your own logic. But what if you want to allow null values, both on their left and right sides? In this video, Sebastian answers this question:
45+
In Kotlin, you can override operators like addition and subtraction for your classes and supply your own logic. But what if you want to allow null values, both on their left and right sides? In this video, Sebastian Aigner answers this question:
4646

4747
<video width="560" height="315" href="x2bZJv8i0vw" title="Kotlin Tips: Operator Functions With Nullable Values"/>
4848

4949
## Timing code
5050

51-
Watch Seb give a quick overview of the [`measureTimedValue()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.time/measure-timed-value.html) function, and learn how you can time your code:
51+
Watch Sebastian Aigner give a quick overview of the [`measureTimedValue()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.time/measure-timed-value.html) function, and learn how you can time your code:
5252

5353
<video width="560" height="315" href="j_LEcry7Pms" title="Kotlin Tips: Timing Code"/>
5454

5555
## Improving loops
5656

57-
In this video, Sebastian will demonstrate how to improve [loops](control-flow.md#for-loops) to make your code more readable, understandable, and concise:
57+
In this video, Sebastian Aigner will demonstrate how to improve [loops](control-flow.md#for-loops) to make your code more readable, understandable, and concise:
5858

5959
<video width="560" height="315" href="i-kyPp1qFBA" title="Kotlin Tips: Improving Loops"/>
6060

@@ -66,7 +66,7 @@ In this episode, Kate Petrova shows three tips to help you work with [Strings](s
6666

6767
## Doing more with the Elvis operator
6868

69-
In this video, Sebastian will show how to add more logic to the [Elvis operator](null-safety.md#elvis-operator), such as logging to the right part of the operator:
69+
In this video, Sebastian Aigner will show how to add more logic to the [Elvis operator](null-safety.md#elvis-operator), such as logging to the right part of the operator:
7070

7171
<video width="560" height="315" href="L9wqYQ-fXaM" title="Kotlin Tips: The Elvis Operator"/>
7272

docs/topics/ksp/ksp-multiplatform.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ In a multiplatform project, Kotlin compilation may happen multiple times (`main`
4444
So is symbol processing. A symbol processing task is created whenever there is a Kotlin compilation task and a
4545
corresponding `ksp<Target>` or `ksp<SourceSet>` configuration is specified.
4646

47-
For example, in the above `build.gradle.kts`, there are 4 compilations: common/metadata, JVM main, Linux x64 main, Linux x64 test,
47+
For example, in the above `build.gradle.kts`, there are 4 compilation tasks: common/metadata, JVM main, Linux x64 main, Linux x64 test,
4848
and 3 symbol processing tasks: common/metadata, JVM main, Linux x64 test.
4949

5050
## Avoid the `ksp(...)` configuration on KSP 1.0.1+

0 commit comments

Comments
 (0)