dongliao8069 2016-08-04 11:43 采纳率: 0%
浏览 384
已采纳

将符号定义为UserID还是UserId?

In Go I've seen some people defining symbols (methods, variables, etc) like this: UserID, GetSomeURL() with UPPERCASE letters of ids, urls, etc.

Is this a standard way?

Even my editor, that uses go-lint, warns me that I should change it (because I use UserId).

I read some of the golang source code https://golang.org/src/ and I never saw some like UserID.

Is this going to be another "tabs" vs "spaces" thing? LOL

I know this does not cause any problems compiling or any other problem, but I'm just trying get some "standard" on this.

  • 写回答

1条回答 默认 最新

  • dongque1958 2016-08-04 11:53
    关注

    UserID and GetSomeURL (or simply SomeULR()) would be idiomatic.

    Source: https://github.com/golang/go/wiki/CodeReviewComments#initialisms:

    Words in names that are initialisms or acronyms (e.g. "URL" or "NATO") have a consistent case. For example, "URL" should appear as "URL" or "url" (as in "urlPony", or "URLPony"), never as "Url". Here's an example: ServeHTTP not ServeHttp.

    This rule also applies to "ID" when it is short for "identifier," so write "appID" instead of "appId".

    You are right, golint is useful to identify deviations from the standard naming convention - it's good to follow its advices (especially when the code is worked on by multiple people and coding style consistency is even more valuable).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记