You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adjust grammar usage when describing uppercase, lowercase, camelCase, Pascal case, and other style cases; replace word "case" with synonyms when not describing one of the cases above (e.g. "example", "circumstance", etc.)
Names of functions, properties and local variables start with a lowercase letter and use the camel case and no underscores:
150
+
Names of functions, properties and local variables start with a lowercase letter and use camel case with no underscores:
151
151
152
152
```kotlin
153
153
funprocessDeclarations() { /*...*/ }
@@ -181,8 +181,8 @@ class MyTestCase {
181
181
### Property names
182
182
183
183
Names of constants (properties marked with `const`, or top-level or object `val` properties with no custom `get` function
184
-
that hold deeply immutable data) should use uppercase underscore-separated ([screaming snake case](https://en.wikipedia.org/wiki/Snake_case))
185
-
names:
184
+
that hold deeply immutable data) should use all uppercase, underscore-separated names following the ([screaming snake case](https://en.wikipedia.org/wiki/Snake_case))
185
+
convention:
186
186
187
187
```kotlin
188
188
constvalMAX_COUNT=8
@@ -201,7 +201,7 @@ Names of properties holding references to singleton objects can use the same nam
201
201
valPersonComparator:Comparator<Person> =/*...*/
202
202
```
203
203
204
-
For enum constants, it's OK to use either uppercase underscore-separated names ([screaming snake case](https://en.wikipedia.org/wiki/Snake_case))
204
+
For enum constants, it's OK to use either all uppercase, underscore-separated ([screaming snake case](https://en.wikipedia.org/wiki/Snake_case)) names
205
205
(`enum class Color { RED, GREEN }`) or upper camel case names, depending on the usage.
206
206
207
207
### Names for backing properties
@@ -257,11 +257,8 @@ if (elements != null) {
257
257
### Horizontal whitespace
258
258
259
259
* Put spaces around binary operators (`a + b`). Exception: don't put spaces around the "range to" operator (`0..i`).
260
-
261
260
* Do not put spaces around unary operators (`a++`).
262
-
263
261
* Put spaces between control flow keywords (`if`, `when`, `for`, and `while`) and the corresponding opening parenthesis.
264
-
265
262
* Do not put a space before an opening parenthesis in a primary constructor declaration, method declaration or method call.
266
263
267
264
```kotlin
@@ -274,28 +271,23 @@ fun bar() {
274
271
}
275
272
```
276
273
277
-
* Never put a space after `(`, `[`, or before `]`, `)`
278
-
279
-
* Never put a space around `.` or `?.`: `foo.bar().filter { it > 2 }.joinToString()`, `foo?.bar()`
280
-
281
-
* Put a space after `//`: `// This is a comment`
282
-
283
-
* Do not put spaces around angle brackets used to specify type parameters: `class Map<K, V> { ... }`
284
-
285
-
* Do not put spaces around `::`: `Foo::class`, `String::length`
286
-
287
-
* Do not put a space before `?` used to mark a nullable type: `String?`
274
+
* Never put a space after `(`, `[`, or before `]`, `)`.
275
+
* Never put a space around `.` or `?.`: `foo.bar().filter { it > 2 }.joinToString()`, `foo?.bar()`.
276
+
* Put a space after `//`: `// This is a comment`.
277
+
* Do not put spaces around angle brackets used to specify type parameters: `class Map<K, V> { ... }`.
278
+
* Do not put spaces around `::`: `Foo::class`, `String::length`.
279
+
* Do not put a space before `?` used to mark a nullable type: `String?`.
288
280
289
281
As a general rule, avoid horizontal alignment of any kind. Renaming an identifier to a name with a different length
290
282
should not affect the formatting of either the declaration or any of the usages.
291
283
292
284
### Colon
293
285
294
-
Put a space before `:` in the following cases:
286
+
Put a space before `:` in the following scenarios:
295
287
296
-
*when it's used to separate a type and a supertype
297
-
*when delegating to a superclass constructor or a different constructor of the same class
298
-
*after the `object` keyword
288
+
*When it's used to separate a type and a supertype.
289
+
*When delegating to a superclass constructor or a different constructor of the same class.
290
+
*After the `object` keyword.
299
291
300
292
Don't put a space before `:` when it separates a declaration and its type.
301
293
@@ -1062,14 +1054,14 @@ Learn the difference between [Java and Kotlin multiline strings](java-to-kotlin-
1062
1054
1063
1055
### Functions vs properties
1064
1056
1065
-
In some cases, functions with no arguments might be interchangeable with read-only properties.
1057
+
In some scenarios, functions with no arguments might be interchangeable with read-only properties.
1066
1058
Although the semantics are similar, there are some stylistic conventions on when to prefer one to another.
1067
1059
1068
1060
Prefer a property over a function when the underlying algorithm:
1069
1061
1070
-
*does not throw
1071
-
*is cheap to calculate (or cached on the first run)
1072
-
*returns the same result over invocations if the object state hasn't changed
1062
+
*Does not throw.
1063
+
*Is cheap to calculate (or cached on the first run).
1064
+
*Returns the same result over invocations if the object state hasn't changed.
1073
1065
1074
1066
### Extension functions
1075
1067
@@ -1137,10 +1129,10 @@ For the guidance on choosing the right scope function for your case, refer to [S
1137
1129
1138
1130
When writing libraries, it's recommended to follow an additional set of rules to ensure API stability:
1139
1131
1140
-
* Always explicitly specify member visibility (to avoid accidentally exposing declarations as public API)
1132
+
* Always explicitly specify member visibility (to avoid accidentally exposing declarations as public API).
1141
1133
* Always explicitly specify function return types and property types (to avoid accidentally changing the return type
1142
-
when the implementation changes)
1134
+
when the implementation changes).
1143
1135
* Provide [KDoc](kotlin-doc.md) comments for all public members, except for overrides that do not require any new documentation
1144
-
(to support generating documentation for the library)
1136
+
(to support generating documentation for the library).
1145
1137
1146
1138
Learn more about best practices and ideas to consider when writing an API for your library in the [Library authors' guidelines](api-guidelines-introduction.md).
0 commit comments