DroidsOnRoids/android-style-guide

Name: android-style-guide

Owner: Droids On Roids

Description: null

Created: 2017-03-27 06:01:05.0

Updated: 2017-10-31 10:46:28.0

Pushed: 2017-04-24 06:57:40.0

Homepage: null

Size: 7

Language: null

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Droids On Roids: Android Code Style

Config
Android Studio

Every DOR Android team member should use this code formatting style in Android Studio:

dor-android-studio-code-style.xml

This ensures formatting consistency across projects. It also makes code review more pleasant, as it reduces time spent on checking things like missing spaces, wrong indents, etc.

SonarQube

SonarQube is a code inspection tool that helps you:

It won't break your builds, but it will judge you and your code by commenting your commits uploaded for review.

Local config

You can also run SonarQube locally in your project without waiting for a remote build to complete. See the official guide for reference:

Analyzing with SonarQube Scanner for Gradle

SonarLint

SonarLint is an Android Studio plugin. It can connect to an external SonarQube server and analyze code on-the-fly, similar to the built-in default Lint functionality.

I think you can handle the plugin config within Android Studio.

If it doesn't work out of the box, you'll have to use a different JDK with JCE unlimited strength policy:

Code style

There is no strict code style that you have to follow. Instead, please refer to some good existing ones:

The only rule you should go by is to be consistent within a project.

Specific topics
Kotlin
Code style

Please refer to Kotlin's website: Kotlin Coding Conventions

XML

Kotlin Android Extensions automatically bind XML-defined views. This allows us to call them through synthetic properties without manually using findViewById() or Butterknife.

Considering that, use lowerCamelCase when naming views in XML files (in contrast to snake_case in Java projects).

Tests

When naming tests, use backticked method names for better readability:

 Methods with braces or as assignment?

he method body is simple or short enough to fit in the same line, use the **assignment operator ( = )**, otherwise use **braces ( { } )**.

 Loops or streams?

ider streams when iterating (instead of typical for loops), as they can often make the code more concise and readable.

Hungarian notation
arian notation (private/static fields starting with m/s) is generally **not recommended**. Here's a good write-up on why not:

t Say mNo to Hungarian Notation (Jake Wharton)](http://jakewharton.com/just-say-no-to-hungarian-notation/)

ou wish to easily remove it from an existing project, see this article about the **Structural Search and Replace** feature of Android Studio:

roid Studio Like a Boss (Realm.io)](https://realm.io/news/360andev-philippe-breault-android-studio-ide-like-boss-structural-search-refactoring-java/)

RxJava/Stream chains

e can get pretty ugly sometimes.

ossible, avoid deep nesting in RxJava/Stream chains. Instead, try to refactor operator arguments into separate methods. A good rule of thumb for clean and readable chains: **one line = one operator**.

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.