46 lines
704 B
Markdown
46 lines
704 B
Markdown
# Kotlin Coding Guidelines
|
|
|
|
## Code structure
|
|
|
|
- short methods (not too long)
|
|
- add suggestion how to refactor
|
|
|
|
- only one level of abstraction
|
|
keep only one abstraction level in method
|
|
|
|
- keep low level of identation
|
|
less is more
|
|
for example when() if-else if-else is not very good redable
|
|
|
|
- use variable for expression / condition
|
|
|
|
|
|
## Questions
|
|
|
|
### `value.?let` or `if (value != null)`
|
|
|
|
Is really better to use
|
|
|
|
```kotlin
|
|
value?.let {
|
|
// some block
|
|
}
|
|
```
|
|
|
|
then
|
|
|
|
```kotlin
|
|
if (value != null) {
|
|
// some block
|
|
}
|
|
```
|
|
|
|
There is no return value so block is NOT expression.
|
|
|
|
### Don't use anonymous class implementation
|
|
```kotlin
|
|
val value = object : Type {
|
|
// implementation
|
|
}
|
|
```
|