Android Code Convention.pptx


文档分类:研究报告 | 页数:约15页 举报非法文档有奖
1/15
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/15
文档列表 文档介绍
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

Android Code Convention 来自淘豆网m.daumloan.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息
  • 页数15
  • 收藏数0 收藏
  • 顶次数0
  • 上传人yzhluyin9
  • 文件大小0 KB
  • 时间2016-07-12