A presentation conducted on 21-10-2022 at Droidcon Egypt 22 #dcegy22 showing the different approaches to implement async programming and how is Kotlin coroutines compared to them and solve their common problems.
1. A Journey from
Callback Hell
to
Kotlin Coroutines
Ahmed Nabil
Kotlin Egypt
@AhmedNMahran
Fri. Oct 21 2022
2. About Me
About Me
● Writing Code since I was 11
● ~10 years in Mobile App development
● Given talks to thousands of audiences
● Prev. Android Mentor at 1M Arab Coders.
● Worked at Hungerstation,Codly, and others.
● Software Tech. Lead at Vodafone (_VOIS).
● Head of Kotlin Egypt.
● Content creator (videos/articles)
Fri. Oct 21 2022
4. About Me
Kotlin
● A modern Programming Language.
● Developed by Jetbrains & Open-Source community
● Since 2010.
● Current Stable Version is 1.7.20 (as of 20-10-2022)
Fri. Oct 21 2022
5. About Me
Used to develop
● Multiplatform-Mobile
● Server-Side
● Web Front-End
● Android
● WatchOS
● Data Science
● and more
Fri. Oct 21 2022
9. About Me
ANR
● any operation > 16ms
may cause Lag
● I/O operations,
long-running operation
● Main thread should ONLY
do UI operations
Fri. Oct 21 2022
15. About Me
Threads Limitations
● Expensive
● Not Infinite, limited with device capabilities
● Not always available, (e.g. JS doesn’t have threading)
● Hard to Error-handle and debug
Fri. Oct 21 2022
22. About Me
Limitations
● Nested Callbacks not easy to understand
● Return Type :
Needs changing the models (extra steps in getting the
data)
● Hard to Error-handle and debug
Fri. Oct 21 2022
26. About Me
Coroutines
● No new apis needed, same language used (kotlin)
● Return type doesn’t change.
● Write sequential code while being thread-safe
● Lightweight, can run many of them in one thread,
● Easy to switch between threads
● Platform independent
● Easy to debug and detect errors.
Fri. Oct 21 2022