kotlin-style-guide
kotlin-style-guide copied to clipboard
Work-in-progress notes for the Kotlin style guide
If you declare a factory function for a class, don't give it the same name as the class itself. Use a distinct name making it clear why the behavior of...
Use top-level objects only if the instances of those objects will be passed somewhere (in other words, if the objects extend a base class or implement an interface). Do not...
When making a function with a lambda parameter prefer a simple lambda without a receiver: ``` kotlin // simple lambda: fun foo(operation: (A) -> Unit) {} // lambda with receiver...
If the class header (primary constructor and superclass list) doesn't fit on a single line, put the opening curly brace of the class on a separate line, with no indentation....
I was wondering what are the views on vertical formatting, e.i. putting similar code one under another: ``` val width = 111 + n + listOf(239, 100500, 10).max() val height...
If the function signature doesn't fit on a single line, I propose the following syntax, similar to the class header syntax proposed by me in #2: ``` kotlin fun longMethodName(...
How to to properly break line cast (`as`, `as?`) or colon (`:`) is present and it doesn't fit in one line? I think variants 1 and 2 are good, 3...
In the process of language evolution, subtle changes may happen to overload resolution algorithms, so it's advisable to design one's overloads so that they all "do the same thing", and...
If a declaration has multiple modifiers, always put them in the following order: ``` public / protected / private / internal final / open / abstract override inner enum /...
Do NOT use `functional expression` in the short function declaration form without curly braces. // Good: full declaration form fun(): Int { return 1 } // Bad: short declaration form...