DEV Community

Discussion on: Make your code beautiful with Kotlin Property Delegates

Collapse
 
ansman profile image
Nicklas Ansman Giertz • Edited

Delegates are very useful but making disk I/O or network calls using delegates are highly discouraged. Instead use an scope.async { loadStuff() } and read it from a suspending function if you want to cache the result. The kotlin style guide explicitly discourages you from making most of your examples delegates or properties:
kotlinlang.org/docs/reference/codi...

Lastly delegates are fairly expensive (they need to create a KProperty object for each property) and on performance sensitive platforms (such as Android) they should be used with care.

Great article though, they are a powerful tool that every Kotlin developer should have in their arsenal