Skip to content

CodeStyle

cketti edited this page Jan 5, 2015 · 17 revisions

K-9 Code Style

We're currently using the code style as specified in settings.jar. In Android Studio go to File > Import settings… and select the file. It will create a new code style profile called "K-9 Mail". None of your global settings will be overwritten!

At the time of this writing (2015-01-05) the code style is not enforced and most of the code base doesn't conform to it, e.g. in many places fields are still prefixed with "m".
If your changes touch a lot of files please don't reformat all of the affected files to use the new code style as this will make it much harder to merge existing branches. You should, however, try to use the code style for new code.
If you decide to fix the code style of a file/method, please do so in a separate commit that doesn't contain any functional changes.

Note: It would be great if you could extract the code style rules from the settings file and put them here in human readable form.

General code quality

  • Use meaningful names for fields, variables, methods and classes.
  • Try to keep methods small.
  • Try to keep classes small.
  • Avoid comments. If you need comments to explain something, chances are your code needs more meaningful names. If you're working around quirks/bugs in Android or a library, please do add a comment explaining why your work-around is necessary.
  • Do not use K9.app in new code!

Over the years many different people have worked on K-9 Mail. In many cases K-9 Mail's code base is not a good example on how to write clean code. You're welcome to improve this situation with pull requests!

Please don't be afraid to submit pull requests even if you believe you can't meet the code quality standards we aspire to. Github's comment system for pull requests is a good tool that allows us to work together on improving the pull request.

Line endings

We're trying to make sure all source and resource files consistently use LFs as line delimiters to avoid merge conflicts.

On Windows, the easiest way to handle this is to have git do it for you. By executing $ git config --global core.autocrlf true at any command prompt. This will cause git to checkout files using Windows-style line endings (CRLF), but all checkins will convert line endings to LF.

On Mac and Linux, you can use $ git config --global core.autocrlf input to make sure you only commit LF line endings.

Clone this wiki locally