This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Bad | |
| fun foo() = foo("a") | |
| fun foo(a: String) { ... } | |
| // Good | |
| fun foo(a: String = "a") { ... } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Bad: use of mutable collection type for value which will not be mutated | |
| fun validateValue(actualValue: String, allowedValues: HashSet<String>) { ... } | |
| // Good: immutable collection type used instead | |
| fun validateValue(actualValue: String, allowedValues: Set<String>) { ... } | |
| // Bad: arrayListOf() returns ArrayList<T>, which is a mutable collection type | |
| val allowedValues = arrayListOf("a", "b", "c") | |
| // Good: listOf() returns List<T> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Avoid doing this: | |
| /** | |
| * Returns the absolute value of the given number. | |
| * @param number The number to return the absolute value for. | |
| * @return The absolute value. | |
| */ | |
| fun abs(number: Int) = ... | |
| // Do this instead: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| foo { | |
| context: Context, | |
| environment: Env | |
| -> | |
| context.configureEnv(environment) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| appendCommaSeparated(properties) { prop -> | |
| val propertyValue = prop.get(obj) // ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun foo() { | |
| ints.forEach lit@{ | |
| // ... | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| list.filter { it > 10 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| drawSquare( | |
| x = 10, y = 10, | |
| width = 100, height = 100, | |
| fill = true | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| when (foo) { | |
| true -> bar() // good | |
| false -> { baz() } // bad | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun parsePropertyValue(propName: String, token: Token) { | |
| when (token) { | |
| is Token.ValueToken -> | |
| callback.visitValue(propName, token.value) | |
| Token.LBRACE -> { // ... | |
| } | |
| } | |
| } |