好命名胜于任何注释
— 51CTO/至简李云
编程过程中使用单词缩写可以提高效率,本文则记录 Android 开发中一些常用的缩写。
标识符命名也是讲究基本规则的:
- 拒绝按照拼音命名,比如
String caidanming; // 菜单名
- 拒绝比上者更甚的做法——使用拼音缩写,比如
String cdm; // 菜单名
- 除了约定俗成的缩写,尽量不要自造,这样会增加别人阅读代码的成本
单词 | 缩写 | 示例 |
---|---|---|
array | arr | String[] titleArr |
asynchronization | async | |
attribute | attr | AttributeSet attr |
background | bg | int bgColor |
buffer | buf | byte[] buf = new byte[1024] |
button | bt / btn | Button btUpdate |
char | ch | |
configure | conf / config | |
context | ctx | Context ctx |
control | ctrl | |
current | cur | long curTime |
database | db | String dbName |
default | def | int def |
delete | del | delUser() |
description | desc | <string name="about_desc"></string> |
directory | dir | File dirFile |
document | doc | |
error | err | int errCode |
horizontal | horz | int horzLen |
icon | ic | ic_download.png |
image | img | int imgId |
implement | impl | class UserDaoImpl implements IUserDao {} |
index | i / idx | int idx |
information | info | getInfo() |
initial | init | init() |
length | len | for (int i = 0, len = list.size(); i < len; ++i) {} |
library | lib | ./app/libs/ |
maximum | max | final int MAX_LEN = 100 |
memory | mem | getMemSize() |
message | msg | String msg |
millisecond | millis | long timeMillis |
minimum | min | final int MIN_LEN = 1 |
number | num | int num |
object | obj | Object obj |
package | pkg | getPkgName() |
parameter | param | |
password |
pwd |
String pwd |
picture | pic | int picNum |
position | pos | int pos |
process | proc | Process proc |
property | prop | |
rectangle | rect | rect() |
request | req | |
resource | res | int resId |
response | res | |
second | sec | long timeSec |
select | sel | |
source | src | |
string | str | String dateStr |
summary | sum | int sum |
synchronization | sync | |
system | sys | |
temporary | tmp / temp | String tmpStr |
text | txt | |
user | usr | getUsrName() |
utility | util | class DateUtil {} |
version | v / ver | getVerCode() |
笔者会在开发过程中不断回头添加。如果发现错误或有所补充,欢迎留言。
网友评论