getUserId 还是 getUserID?

2023-01-22 13:10:47 +08:00
 lowsell
类似的 getXxxURL 还是 getXxxUrl
不确定应该用哪种,大家呢
4677 次点击
所在节点    问与答
41 条回复
nexo
2023-01-22 13:13:15 +08:00
ID URL
pdog18
2023-01-22 13:14:39 +08:00
似乎 ID 是合理的
iseki
2023-01-22 13:17:13 +08:00
少于三个字母我选 ID ,三个字母开始我宁可 Url
SuperMild
2023-01-22 13:19:22 +08:00
最标准的是 Id ,URL ,但实际操作没必要太计较。
pupboss
2023-01-22 13:22:55 +08:00
Id 是一个单词 identity 的缩写,url 是 uniform resource locator 缩写,4 楼说的就是标准答案了
hahadaxigua834
2023-01-22 13:28:16 +08:00
Words in names that are initialisms or acronyms (e.g., URL and NATO) should have the same case. URL should appear as URL or url (as in urlPony, or URLPony), never as Url. This also applies to ID when it is short for “identifier”; write appID instead of appId.

https://google.github.io/styleguide/go/decisions#variable-names
hst001
2023-01-22 13:37:57 +08:00
ID 和 URL 都是缩写,通常情况下要么全大写要么全小写
gowl
2023-01-22 13:49:49 +08:00
按微软的命名规则的话是 ID 和 Url 。
SuperMild
2023-01-22 14:42:37 +08:00
@hahadaxigua834 这个竟然是 Google 的 Go 语言风格,与 Go 自己的标准库不一样啊。

比如 https://pkg.go.dev/database/sql#Result 用了 LastInsertId()

以及这里 https://pkg.go.dev/os/user 用了 UnknownUserIdError 和 LookupId() 等
hahadaxigua834
2023-01-22 15:09:42 +08:00
HAWCat
2023-01-22 16:27:58 +08:00
自己统一了就行,各家都不一样的
securityCoding
2023-01-22 18:06:10 +08:00
golanglint-ci 规则强制 ID
duke807
2023-01-22 18:56:39 +08:00
get_usr_id()
get_xxx_url()
sifeizhai2020
2023-01-22 18:57:52 +08:00
Now lowercase everything (including acronyms), then uppercase only the first character of:
- ... each word, to yield upper camel case, or
- ... each word except the first, to yield lower camel case

https://google.github.io/styleguide/javaguide.html#s5.3-camel-case
Jooooooooo
2023-01-22 19:31:02 +08:00
ID 是 go 的风格, 写 java 的从来都是 Id
snw
2023-01-22 19:34:38 +08:00
我选 getUserId 和 getXxxUrl. 对于这种很常见的缩写单词,就当它普通单词对待,不然有时出现在函数名中间时维持同样的原则非常难受:getIDAsync, getURLList
lowsell
2023-01-22 20:08:25 +08:00
@snw 确实有遇到这个场景,很是别扭
Knowazz
2023-01-22 20:17:58 +08:00
感觉后者比较顺眼
leonshaw
2023-01-22 20:20:14 +08:00
@snw 两个缩写连着更难受
qeqv
2023-01-22 21:19:10 +08:00
这个问题也是困扰过我,现在我选择 Id Url

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

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

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

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

© 2021 V2EX