- We care about clean code and aim to make this codebase as self-documenting and readable as possible.
- We primarily use Kotlin and follow coding conventions based on the Android Kotlin Style Guide
- There may be instances of code that pre-dates our use of this style guide, these can be refactored as we encounter them.
To adhere to codestyle, please run ./gradlew spotlessApply
to autoformat in order to fix any CI issues.
If you want to do this automatically upon commit we recommend the following pre-commit
hook.
❯ cat .git/hooks/pre-commit
./gradlew :app:spotlessApply
git add `git diff --name-only`
exit 0
If you want to reformat code whilst writing it, please make sure you have installed and enabled the IntelliJ Ktfmt plugin, with Dropbox Style selected.
When logging with Timber we use the new Kotlin styles strings
Timber.w("Loading $url")
Rather than C style strings
Timber.w("Loading %s", url)
Mixing the two styles within a single statement can lead to crashes so we have standardized on the more readable Kotlin style. This is slightly less efficient - should efficiency become an issue we can use proguard to optimize away log statements for releases.
Case in package names is problematic as some file system and tools do not handle case sensitive file changes well. For this reason, we opt for lowercase packages in our project. Thus we have:
package com.duckduckgo.app.trackerdetection
rather than:
package com.duckduckgo.app.trackerDetection
We use the when then convention for test:
when <condition> then <expected result>
For example:
whenUrlIsNotATrackerThenMatchesIsFalse()