1 Android Code Conventions July 1,2011. 2 Why Code Conventions ? 80 % of the lifetime cost of a piece of software goes to maintenance. ? Hardly any software is maintained for its whole life by the original author. ? Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. ? If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. 3 Principal ? The rules below are not guidelines or mendations, but strict rules. ? Changes will not be accepted if they do not adhere to these rules. ? Not all existing code follows these rules, but all new code is expected to. 4 Indentation ? Use four spaces as the unit of indentation . ? DON ’ T use tabs ? Avoid lines longer than 100 characters ? Exception: if ment line contains an mand or a literal URL longer than 100 characters, that line may be longer than 100 characters for ease of cut and paste. ? Exception: import lines can go over the limit because humans rarely see them. This also simplifies tool writing. 5 Declarations ? One declaration per line ? Try to initialize local variables where they ’ re declared . int level, size; int level; // indentation level int size; // size of table 6 Don't Ignore Exceptions ? Throw the exception up to the caller of your method ? Throw a new exception that's appropriate to your level of abstraction ? Handle the error gracefully and substitute an appropriate value in the catch {} block. ? Catch the Exception and throw a new RuntimeException . This is dangerous: only do it if you are positive that if this error occurs, the appropriate thing to do is crash. ? Last resort: if you are confident that actually ignoring the exception is appropriate then you may ignore it, but you must ment why with a good reason void setServerPort (String value) { try { serverPort = (value); } catch ( NumberFormatExceptio