没有人觉得 golang 官方的项目文件命名规范很奇怪吗? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
ysmood
V2EX    程序员

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

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

    比如 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 &bsp;   FAQ     Solana     2538 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 15:05 PVG 23:05 LAX 08:05 JFK 11:05
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86