Kotlin is a modern, concise, and safe programming language that is fully interoperable with Java. It is designed to be more expressive and concise than Java, with features that help avoid common programming errors.
Kotlin Anti-Patterns Overview
Using !! Operator Excessively
!!
operator forces a nullable type to be non-null and throws a NullPointerException
if the value is null. Use safe calls (?.
) and the Elvis operator (?:
) instead.Not Using Data Classes for Simple Data Holders
equals()
, hashCode()
, toString()
, and copy()
methods.Ignoring Nullability in Platform Types
Overusing Extension Functions
Not Using Coroutines for Asynchronous Operations
Not Using Kotlin's Standard Library Functions
Not Using Property Delegation
lazy
, Delegates.observable
, etc.) for common property patterns.Not Using Sealed Classes for State
Not Using Scope Functions
let
, run
, with
, apply
, also
) to make code more concise and readable.Not Using Inline Functions for Higher-Order Functions
inline
for higher-order functions to avoid the overhead of lambda object creation and virtual function calls.Not Using Companion Objects Properly
Not Using Type Aliases for Complex Types
Not Using Extension Properties
Not Using Object Expressions for Interfaces
Not Using Kotlin's Collection Operations
map
, filter
, reduce
, etc.) for more concise and readable code.Not Using Destructuring Declarations
Not Using Kotlin's String Templates
$variable
or ${expression}
) instead of string concatenation for more readable code.Not Using Named Arguments
Not Using Kotlin's Flow for Reactive Programming