没有人觉得 golang 官方的项目文件命名规范很奇怪吗?

2015-04-08 15:35:13 +08:00
 ysmood

比如 http://golang.org/doc/code.html
不用驼峰或者下划线,直接用类似 stringutil.go,然后行文不远又能看到 reverse_test.go 这种下划线式的。这种混用很常见吗?

15183 次点击
所在节点    程序员
11 条回复
zx9597446
2015-04-08 15:45:48 +08:00
习惯就好:)
zhujinliang
2015-04-08 15:47:10 +08:00
xxx_test.go 是单元测试约定的文件命名格式
aaaa007cn
2015-04-08 15:52:40 +08:00
stringutil 不是个 package 么,哪有 stringutil.go

http://golang.org/doc/code.html#PackageNameshttp://golang.org/doc/effective_go.html#names

>> Package names
>> By convention, packages are given lower case, single-word names; there should be no need for underscores or mixedCaps.

>> MixedCaps
>> Finally, the convention in Go is to use MixedCaps or mixedCaps rather than underscores to write multiword names.

reverse_test.go 是因为这是测试所以才下划线了吧

http://golang.org/pkg/testing/

>> To write a new test suite, create a file whose name ends _test.go that contains the TestXxx functions as described here.
ysmood
2015-04-08 17:08:35 +08:00
@aaaa007cn `stringutil` 我笔误。别纠结后缀。关键是文件命名方式。
ysmood
2015-04-08 17:09:45 +08:00
stringutil 这个不就两个单词么?should be single-word 这不自相矛盾吗?
ivanlw
2015-04-08 17:28:39 +08:00
@ysmood 同意,不懂为啥stringutil是single…莫不成它的意思是多个词也不要拆分?
ming2281
2015-04-08 22:30:58 +08:00
你去看看Python的文档,多了去了,比如splitext(pathname)
习惯就好
aaaa007cn
2015-04-09 00:30:37 +08:00
可能是与其 string_util 或者 stringUtil 他们宁愿选择 stringutil
看看正式代码中
/src/cmd/addr2line
/src/cmd/objdump
/src/image/internal/imageutil
/src/index/suffixarray
也都是选择全部小写,不下划线,不驼峰
ewex
2015-04-09 01:38:08 +08:00
挺好的,我一直都这样写
比驼峰看起来优美
相比下划线或连接线又可以双击选择
leecade
2015-04-09 02:16:59 +08:00
文件命名方式没有特别规范吧, 包名要考虑默认引入后就是引用名, 建议是纯小写, 不过我看常用包各种命名都有, 尽量纯小写吧

ref: http://golang.org/doc/effective_go.html#package-names
ysmood
2015-04-09 11:21:04 +08:00
@ewex 比如 whydoyouthinkitiselegant?

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

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

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

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

© 2021 V2EX