When we talk about refactoring the code, the very first thing which comes to mind is that “Why to change something which already works”. We often convince ourselves by telling that we should focus more on fixing customer issues, adding new requirements/features as this is the area from where actual money comes in. While we focus on making customers happy, we often forget the other side of the coin which is to make developers happy as well since they are the one who has to work on that codebase for many years. And we all have felt this pain while debugging a bulky, lengthy and tight coupled codebase.
There’s one modernization practice which we as an android developer adapt every year without fail. Yes, you guessed it right! It’s target API level requirements which have been made mandatory by Google since November 2018. Targeting to recent API level ensures that users get to benefit from significant security and performance improvements. While we do this transition religiously every year, we often ignore to adapt other platform features which can make both users and developers happy. Let’s see below what I mean by this.
What makes our users happy ?
- Dark mode support: Dark mode is probably one of the most popular features in the modern user interface. From apps to operating systems, Apple to Google, smartphones to laptops, many of the products we use today have some type of dark mode integrated into the user interface. Not only it is good for our eyes but also it saves lots of battery consumption. If we don’t choose to modernize the app by implementing dark mode support in the app, users gradually would start to avoid using the app at all.
- Latest UI widgets and animations: Users want to have a consistent experience while browsing apps in their devices. If they see any deviation in any app, it might be a little annoying to them. Today most of the apps use various material design components combined with proper animations which bring newness in look and feel of the app. Imagine users open your app and see very old and outdated UI widgets, it might cause a turn off and they might start looking to find a better replacement for your app.
- Multi-Window and Picture-in-Picture support: Modern users love to multitask throughout their day. Adding support for multi-window and picture-in-picture will increase productivity and improve user experience a lot. Although not having these features might not be as bad as above mentioned features but at the same time, it adds lots of value if implemented correctly in the app.
There are many other such examples which we can adapt/implement in our app to make it look modern with time so that we don’t get left behind. Now, let’s see how developers can benefit from modernizing the apps regularly.
What makes our developers happy ?
As Martin Fowler said in his Refactoring book:
“When you think about programmers, most of us will think that they spend most of their time writing code. Actually, this is quite a small fraction. Programmers spend most of their time reading the code and debugging it. Every programmer can tell a story of a bug that took a whole day (or more) to find. Fixing the bug is usually pretty quick, but finding it is a nightmare.”
We can clearly see the importance of well-written code as it’s easier to read and maintain. Let’s see what are various ways which we as an android developer can adapt to make our life easier.
- Start using Kotlin: Developers around the world want to write as least code as possible and still achieve their objectives. Kotlin helps the developer to write better apps faster and with less code. Since it’s fully compatible with Java, you can start using Kotlin in your app from today. Let’s see some advantages of using Kotlin below.
Data class makes code concise and easy to read
Kotlin way of handling NullPointerException
- Use Jetpack components: Jetpack is a suite of libraries which help developers follow best practices, reduce boilerplate code, and write code that works consistently across Android versions and devices so that developers can focus on the code they care about. These libraries make day to day life of developers very easy. They take care of managing activity lifecycles, survive configuration change (major pain area of any developer) and help to prevent memory leaks in the app. So now developers can focus on implementing business logic and leave other important details for android to handle.
- Consider using CameraX: Whoever has worked on camera APIs earlier knows the pain point of using it. Developers needed to take care of the lifecycle and add device-specific code in the codebase to resolve device compatibility issues. And even after investing multiple hours in development, we never used to get the same experience which preinstalled/native camera app provides. So Google has come up with CameraX library (part of Jetpack) to make development easier. It provides a consistent and easy-to-use API surface that works across most Android devices.
- Be flexible in adapting new app architecture: Don’t shy away from adopting a new architecture if it suits your requirement in a better way. The thing about architecture is that it doesn’t last long and it changes frequently with time and requirements. So always be proactive on this front. I had recently written an article about switching from MVP (A famous app architecture once upon a time) to MVVM (Google recommended app architecture), you can read it here.
Now that we have seen multiple examples of modernizing apps which make users and developers both very happy, I’m sure most of you will start thinking towards implementing some of them in your codebase starting today. Don’t wait for a perfect time to start refactoring/modernizing your apps as you might almost never get time to do so. Build a habit to make incremental change daily and you will see its results in no time. Don’t wait for something to get broken to implement the change, but take proactive actions and update before it gets old.