好的变量缩写

2015-09-08 22:36:01 +08:00
 DjvuLee

自己觉得 3~4 个字符表示的缩写给程序变量命名比较好,即避免了单个字符的完全没有意义,也避免了冗余,我自己个人编程中觉得下面这些是不错的,不知道大家通常有哪些不错的缩写?

idx: index
cnt: count
src: srouce
dst: destination
usr: user
ptr: pointer
msg: message
buf: buffer
len: length
dat: data
lib: library
inc: increase
dec: decrement
rsp: response
req: request

addr: address
conn: connection

6425 次点击
所在节点    编程
32 条回复
ehs2013
2015-09-09 09:20:28 +08:00
@NearTan In the original Unix implementations, /usr was where the home directories of the users were placed (that is to say, /usr/someone was then the directory now known as /home/someone ). In current Unices, /usr is where user-land programs and data (as opposed to 'system land' programs and data ) are. The name hasn't changed, but it's meaning has narrowed and lengthened from "everything user related" to "user usable programs and data". As such, some people may now refer to this directory as meaning 'User System Resources' and not 'user' as was originally intended.
zylll520
2015-09-09 09:21:50 +08:00
个人习惯没有超过 5 个就不用缩写
tabris17
2015-09-09 09:32:48 +08:00
src: srouce
dst: destination
ptr: pointer
msg: message
buf: buffer
len: length
lib: library
addr: address
conn: connection

这几个长的可以有,而且很常用,一目了然,其他几个本来就很短,没必要再缩写了
Andiry
2015-09-09 10:20:39 +08:00
When Ken Thompson was asked if he redid UNIX, what would he do differently, he said that he'd spell creat with an e.
wuxu92
2015-09-09 10:39:24 +08:00
user 竟然用 usr 。。。 data 缩写为 dat 也没有意义, response 缩写为 resp 的比较多
Raito
2015-09-09 10:42:13 +08:00
srouce? 打错了吧
kappa
2015-09-09 10:43:00 +08:00
inc: increase
dec: decrement

这。。。
lxrmido
2015-09-09 11:08:24 +08:00
pwd/passwd/password
desc/description
fs/filesystem
res/resource
db/database
jhaohai
2015-09-09 11:11:43 +08:00
最令人发指的是把变量名缩的只剩一个字符
把 request 缩成 r
把 header 缩成 h
把 packet 缩成 p
pangtianyu
2015-09-09 11:31:31 +08:00
我认为最好的变量就是 a 到 z 一共 26 个字母 不够就 aa ab 一直下去
jswh
2015-09-09 11:33:02 +08:00
代码自注释
learnshare
2015-09-09 11:43:51 +08:00
尽量不缩写,靠 IDE/编辑器的自动提示来提高效率

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/219240

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX