Points to keep in mind when reviewing Android databases
Code review is a tedious process sometimes, but I think we need to spend more time on it. Perhaps it is an opportunity for you to learn or share some knowledge.
I have listed some points which I consider necessary to check the code review process in Android projects.
Imagine the following situation: Nice app but slow at the same time, switching between screens gets slower every time.
Some points to check while reviewing the code:
- Is there any
ContextKeep this new piece of code?
- Is there any RxAndroid related code? If yes, check if RxCalls gets dumped at end of lifecycle scope (ViewModel/Fragment/Activity).
- If the icon contains coroutines, check if it is a file
ViewModelScope to be edited correctly.
- Is the code some kind of implementation using
CountDownTimer, AsyncTask, or any video/audio player? If yes, then the code should fire the memory source related to avoiding the leak.
- Is it a new part? with
ViewBindingapproach, the code should release the binding In the
Sometimes we have a file
ViewGroup This has something else
ViewGroup as a child.
guDr Always suggest to use it as
ViewGroup constraint charts To keep layouts flat. It can avoid exceeding the limit which causes performance problems.
There are some tips mentioned in the Android docs to reduce overdraft.
Every resource in the Android world has an identifier, which is an integer type. How do we make sure that an integer value represents a valid resource identifier? Annotations help us with this.
In the above code, the reviewer could suggest: “What do you think about using annotations? Something like this:” (show example):
Other examples of annotations: here.
It is very important to invest time during code reviews. Try to think as the author thinks, reflect his choices, and ask questions to understand the code.
A new icon is coming. wait: “This code does the same thing we already have in this component.” Comments like this are necessary because the great thing is to reuse what is already in our code base. Pay attention when the ingredients are something like:
- The X component changes the color of the moon to red 🔴;
- The Z component changes the full moon to blue 🔵;
- Component A changes the moon to green 🍏.
Why is there no element to change the color of any moon? You can receive the color as an argument. Is there a lot of work?
If you have a sensitive icon – I love the expression Danger areaWho best describes this situation. The danger code is the code that the reviewer looks at and gives a reaction like: This symbol has no meaning.
In this case, do not judge the author. Talk to them to understand the reason behind this symbol. This talk may be an opportunity to learn something new.
Software architecture is a specific communication protocol between parts of a program.
Code review is a very effective arm for identifying issues such as syntax violations. Adding comments like this is fine in such scenarios:
- “Friend, your ViewModel is accessing repositories. We have a use case in between. Please take a look at the MainViewModel file, which is a great example.“
- “Why use an adapter reference inside your ViewModel? The adapter is a component of RecyclerView. It would be better to put this in a part and keep it away from our display model.“
- unused imports;
- Unused resources such as drawable items, strings, colors…
- Comment code
- unformatted code;
- Variable names, method names, file names…
- The code does not follow the style guide. For example, Kotlin defines a well-defined style guide. It greatly helps any developer to quickly find any software component in an existing database.
Static analysis tools are useful in the code review process, but they are not 100% effective. A critical developer review is indispensable if your team is looking for code quality.