gpt4 book ai didi

go - 将符号定义为 UserID 还是 UserId?

转载 作者:IT王子 更新时间:2023-10-29 01:50:11 25 4
gpt4 key购买 nike

在 Go 中,我看到一些人像这样定义符号(方法、变量等):UserIDGetSomeURL() 以及 ids、urls 的大写字母,等

这是标准方式吗?

甚至我使用 go-lint 的编辑器也会警告我应该更改它(因为我使用 UserId)。

我看了一些golang源码https://golang.org/src/而且我从未见过像 UserID 这样的东西。

这会是另一个“制表符”与“空格”的区别吗?哈哈

我知道这不会导致任何编译问题或任何其他问题,但我只是想在这方面获得一些“标准”。

最佳答案

UserIDGetSomeURL(或简称为 SomeULR())是惯用的。

来源: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".

你是对的,golint 可用于识别与标准命名约定的偏差 - 遵循它的建议是很好的(尤其是当代码由多人共同编写并且编码风格的一致性更有值(value)时)。

关于go - 将符号定义为 UserID 还是 UserId?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38766425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com