an Automated Code Review Tool for Both Web and Mobile Applications
How Code Quality Is Measured: Android Code Review at Yalantis
Programmers are the authors of great builds just as writers are the authors of bestselling novels. But backside the scenes, in that location are always many people who contribute to the procedure.
The best code – like the all-time products of any type – is the result of collaboration. All programmers, both senior-level software engineers and beginners, occasionally need somebody else to take a fresh look at their lawmaking and find issues in it. This is how nosotros ensure code quality at Yalantis.
We regularly conduct code reviews of our projects since it profoundly increases the lawmaking efficiency streamlines the native app evolution.
In this commodity, we show you why and how nosotros practice lawmaking reviews and give some useful tips on performing a code review .
Goals and benefits of code reviews
Code reviews achieve 4 main goals
We've written code review guidelines and tutorials for our Android team to make the code review process smoothen and transparent. Our guidelines are based on Android code review best practices and techniques to better code quality.
In 2019, Google introduced their ain guides to code review for both developers and lawmaking reviewers. These guides influenced our code review process, and we strongly recommend you cheque them out.
Code review process at Yalantis involves line-by-line lawmaking analysis, a source lawmaking review checklist, and documentation for suggesting improvements. Permit's run into how to practise an Android code review.
Important aspects of code analysis
Below, we've listed the most important aspects a code reviewer should pay attention to.
i. Documentation clarity
At some point you may observe yourself supporting an existing application or substituting a developer. Developers who didn't initially work on a projection demand to clearly understand every single line of code. The clearer the documentation, the faster the app development and the fewer resources your system volition spend.
If code has changed, information technology's important to check whether all related documentation (README, g3doc pages, etc.) accept also been updated. If you delete or deprecate code, consider whether the corresponding documentation should also be deleted. Too, bank check documentation for logic errors.
2. Code styling
Code styling includes several important aspects:
-
Comments
Some comments in code might not make any sense. Or they may exist written in a foreign language. Comments should be clear and useful, and most importantly explicate what should be changed. Our company standard is to utilise English for all comments even though English language is non our native language.
We utilize English for ii reasons:
Developers for Android platform from other countries might use our source code in the future.
We're an active contributor to open-source software that's widely used past other companies around the globe. Bank check out uCrop, our open-source image cropping library for Android that's used by TripAdvisor and Pinterest, and see our other iOS and Android open up-source projects.
-
Naming
Naming conventions make Android code more understandable. All naming conventions are specified in our Yalantis internal Android lawmaking guidelines.
If yous don't take conventions in your team, you tin can use naming conventions from the Android Open Source Projection, which has a structured list of useful naming examples.
In that location are too some details y'all should pay attending to like file structure, syntax errors, employ of brackets and white spaces, etc. Create your own mode guide with code standards or use a well-known guide such as the Kotlin mode guide from Android Developers or the Coffee Style Guide from Google. And of course, "Clean Code: A Handbook of Active Software Craftsmanship" has an all-encompassing set of recommendations on clean coding and lawmaking styling.
Here's a snippet of code from our uCrop project to show how we proper noun fields and methods and how we write comments:
public static final bladder DEFAULT_MAX_SCALE_MULTIPLIER = x.0f; private final RectF mCropRect = new RectF(); individual final Matrix mTempMatrix = new Matrix(); private float mTargetAspectRatio; /** * This method changes the image scale for a given value related to indicate (px, py) but only if * resulting scale is in min/max bounds. * * @param deltaScale - scale value * @param px - scale center X * @param py - calibration middle Y */ public void postScale(float deltaScale, float px, float py) { if (deltaScale > 1 && getCurrentScale() * deltaScale <= getMaxScale()) { super.postScale(deltaScale, px, py); } else if (deltaScale < one && getCurrentScale() * deltaScale >= getMinScale()) { super.postScale(deltaScale, px, py); } }
3. Architectural patterns
An app architecture is a design for the project. It defines the work assignments that must be carried out by the design and implementation teams. A software architecture dictates technical standards and how the app architecture should be congenital.
When we exercise code review for Android projects, we check if the architectural blueprint is implemented correctly (i.ะต. if the business organization logic is decoupled from the view layer). We as well check the purity and correctness of the connections between components.
For example, nosotros employ the Model–View–ViewModel (MVVM) architectural pattern and Make clean Compages approach for Android app evolution. During a code review, nosotros cheque that a developer has followed the principles of these architectural patterns.
4. Simplicity
At Yalantis, we follow the KISS principle (Go on Information technology Short and Simple), according to which simplicity should exist a key goal in design and unnecessary complication should be avoided.
When conducting a code analysis, it's crucial to brand certain that code can exist easily understood by other developers and that making changes won't lead to the appearance of new bugs. Check that classes and functions aren't overly circuitous and that there's no superfluous functionality.
5. Mistake handling
Error treatment is crucial for whatever software project. At Yalantis, we bank check if the code we're reviewing considers all possible errors arising from user input, server responses, and database transactions.
Error handling isn't merely most logging detected errors. Quite often, fault handling as well involves informing the user about what exactly went wrong in the application and how the issue can exist resolved.
Here's a piece of lawmaking from a ViewModel that illustrates an API request that handles both the outcome and possible errors by calling proper methods in the respective View form:
getUserUseCase .observeUserById(userId) .doOnSubscribe{ progress.value = true } .doOnTerminate{ progress.value = faux } .subscribeBy( onNext = { userLiveData.value = it }, onError = { handleError(it) } ) .addTo(compositeDisposable) 6. Test coverage
Even though we rely heavily on our QA team for successful releases, we don't pass code into production until we've written tests for the specific functionality we're implementing. The test early principle helps us detect and fix bugs early in the project life bicycle.
During Android code inspection, we meet what percentage of lawmaking is actually covered by our unit tests. We pay most attention to unit testing business logic, simply we run UI tests besides. According to the rules in Lars Vogel's tutorial on developing Android unit and instrumentation tests:
-
seventy–80% of tests should exist unit tests to ensure stability of your code base
-
20–30% of tests should be functional tests to ensure that the application really works
7. Performance monitoring
Fifty-fifty though mobile applied science is rapidly developing, the processing power of the average Android device is still express, memory is finite, and battery capacity continues to exist one of the most precious resource. If we don't monitor code functioning, the product nosotros're developing may non laissez passer muster when information technology launches on the market.
App performance depends non only on the reliability of Android source code merely also on tertiary-party SDKs, operating systems, devices, network constraints, data services, and APIs that back up the mobile application.
To observe what causes specific performance problems, we need to have a await under the hood. We use Android Profiler to collect information nearly an app's execution. Nosotros as well use simulators with diagnostic capabilities to quickly pinpoint the root causes of failures when something goes wrong.
For example, if during Android source code review we discover that an app sends frequent requests to the server, nosotros will do clever HTTP caching. If an app causes significant bombardment drain, we'll make sure it doesn't ask location services for unnecessary updates.
viii. Security
The goal of a security code review of Android projects is to detect security vulnerabilities and find weaknesses. The source of these weaknesses can be insufficiently secure coding policies or flaws in the business organization logic, in internal structures, or in the organisation's design.
For example, during our security checks nosotros come across if a programme uses HTTPS/SSL for data transfer between the server and client, verify that data is encrypted, and check if the lawmaking itself is obfuscated.
Our security code review reveals security bugs and hidden backdoors.
Android code review tools
Code review is a proficient development practice, but information technology requires time and effort from the reviewer. And as an app becomes more complex and more developers outset working on the project, more resources are required for code review.
Lawmaking review automation tools facilitate development by regularly checking code against requirements. Here'south a list of the well-nigh popular code review software:
-
Checkstyle is an open-source tool that helps developers check if their code complies with relevant style guides. It optimized for Google's and Sun'due south style guides. Only information technology checks only Java lawmaking.
-
SonarQube is a powerful code analyzer that works with 27 programming languages, works seamlessly with build frameworks, and integrates with popular CI engines like Jenkins TeamCity. Nosotros apply SonarQube for regular code checks in most of our projects.
-
Codacy is a defect tracking system that allows for automated code testing and review. Its static code assay tool lets developers automatically identify and accost security concerns, duplication, complexity, fashion violations, and drops in coverage in every commit and pull asking, directly from their Git workflow. Codacy can hands exist integrated with GitHub, Bitbucket, and Gitlab, and it analyzes 28 different programming languages.
Possible outcomes of a Yalantis code review
For each code review, we create an Android code review checklist and suggest code improvements that can be boiled downward to five types:
-
Refactoring to brand the code cleaner, more than reliable, and more maintainable
-
Fixing the root causes of problems we've detected
-
Rewriting some parts of the code
-
Optimizing operations with a database or an API, or changing a library
-
Rewriting the project from scratch
Let us know if yous have any questions nearly Android code review. We're always happy to help and listen to your feedback.
Want to better your app?
We can assist you lot save your project from sinking
Contact us
Source: https://yalantis.com/blog/how-to-do-code-review-for-android/
0 Response to "an Automated Code Review Tool for Both Web and Mobile Applications"
Post a Comment