V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ysmood
V2EX  ›  程序员

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

  •  
  •   ysmood ·
    ysmood · 2015-04-08 15:35:13 +08:00 · 15145 次点击
    这是一个创建于 3277 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    第 1 条附言  ·  2015-04-08 17:54:07 +08:00
    `stringutil.go` 笔误,应该是 `stringutil`。
    11 条回复    2015-04-09 11:21:04 +08:00
    zx9597446
        1
    zx9597446  
       2015-04-08 15:45:48 +08:00
    习惯就好:)
    zhujinliang
        2
    zhujinliang  
       2015-04-08 15:47:10 +08:00
    xxx_test.go 是单元测试约定的文件命名格式
    aaaa007cn
        3
    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
        4
    ysmood  
    OP
       2015-04-08 17:08:35 +08:00
    @aaaa007cn `stringutil` 我笔误。别纠结后缀。关键是文件命名方式。
    ysmood
        5
    ysmood  
    OP
       2015-04-08 17:09:45 +08:00
    stringutil 这个不就两个单词么?should be single-word 这不自相矛盾吗?
    ivanlw
        6
    ivanlw  
       2015-04-08 17:28:39 +08:00 via iPhone
    @ysmood 同意,不懂为啥stringutil是single…莫不成它的意思是多个词也不要拆分?
    ming2281
        7
    ming2281  
       2015-04-08 22:30:58 +08:00   ❤️ 1
    你去看看Python的文档,多了去了,比如splitext(pathname)
    习惯就好
    aaaa007cn
        8
    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
        9
    ewex  
       2015-04-09 01:38:08 +08:00 via Android
    挺好的,我一直都这样写
    比驼峰看起来优美
    相比下划线或连接线又可以双击选择
    leecade
        10
    leecade  
       2015-04-09 02:16:59 +08:00
    文件命名方式没有特别规范吧, 包名要考虑默认引入后就是引用名, 建议是纯小写, 不过我看常用包各种命名都有, 尽量纯小写吧

    ref: http://golang.org/doc/effective_go.html#package-names
    ysmood
        11
    ysmood  
    OP
       2015-04-09 11:21:04 +08:00
    @ewex 比如 whydoyouthinkitiselegant?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3234 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 14:00 · PVG 22:00 · LAX 07:00 · JFK 10:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.