Global Coroutine scope is scary

Global Coroutine scope is scary

Overview Using suspend methods with coroutines is a new norm while using Kotlin in Android, Kotlin Native or Kotlin Multiplatform. Recently, I have been searching good libraries for the multiplatform for a pet project I am working on, and I have seen many libraries and implementations that uses GlobalScope as coroutine scope. This is a huge antipattern because using GlobalScope can lead to memory leaks. Problem with GlobalScope Though in Android, using suspend methods is fairly easy because you can just use viewModelScope because most of the heavy lifting is being done inside viewmodels. So, No need to switch to CoroutineScope. But occasionally, there is a need for asynchronous work outside ViewModel. A common example of it would be an external SDK in your codebase may require an instance of a class performing module specific or app related tasks. ...

January 29, 2022 · 3 min · SlothieSmooth
Logging for dummies

Logging for Dummies

Overview Logs are very useful while debugging an issue and finding a root cause for it. I would write tons of garbage logs lines such as “inside save image method”, “user clicked on button send” or something like “image-Id=83488131". I would delete all these stuff as soon as I know what is the issue, and ready to commit changes. But, having too much verbosity in logs is equally bad and pollutes the log cat. Yeah, Logs are useful daily but if done properly. Here are a few tips and suggestion that I learned the hard way that would help you up the logging game. ...

November 1, 2021 · 8 min · SlothieSmooth
Naming things in codebase image

Naming things in codebase

Naming your methods and fields while programming can be hard at times, But not impossible and since, there is no concrete guideline about the naming, I made up my own. You can use these guidelines in your codebase to make the code more readable and avoid mental breakdowns for a maintenance programmer. Avoid misleading words Avoid naming your variables data, process, run, do. These words do not mean anything. Literally, any variable in your codebase can be called data, since you are ultimately doing something with data. These words do not correctly inform what they are supposed to do. In such cases, think about it for a few moments and figure out what can be a suitable name for your method or a variable. The generic idea would be avoiding common prefixes that could mislead someone or even you after some months. ...

June 27, 2021 · 4 min · SlothieSmooth