Skip to content
This repository was archived by the owner on Oct 16, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions style.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,38 @@ private val ICON = IconLoader.getIcon("/icons/kotlin.png")

When writing a library, retain the explicit type declaration when it is part of the public API.

### Marking result expressions

If an expression is a result of a multi-line block or lambda then it should be marked with `return@label` statement.

```kotlin
// WRONG!
textView.setOnEditorActionListener { _, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_DONE || event?.keyCode == KeyEvent.KEYCODE_ENTER) {
onPositiveButtonClick()
true
} else {
false
}
}

// Okay
textView.setOnEditorActionListener { _, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_DONE || event?.keyCode == KeyEvent.KEYCODE_ENTER) {
onPositiveButtonClick()
return@setOnEditorActionListener true
}
return@setOnEditorActionListener false
}
```

For single-line lambdas the `return@label` statement shouldn't be used.

```kotlin
list.filter { it > 5 } // Okay
list.filter { return@filter it > 5 } // WRONG!
```


# Naming

Expand Down