Clojure 的命名约定是什么?
任何人都可以解释或指出我在哪里可以找到 clojure 的命名约定:
- 文件名
- 函数(据我所知,函数名称只是破折号分隔的值)
- 变量
Can anyone explain or point me to where I can find clojure's naming conventions for:
- File names
- Functions (From what I understand, function names are simply dash separated values)
- Variables
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可能需要查看开发人员的 Clojure 库编码标准维基 - 这可能是我见过的最全面的列表。
更新:上面的链接似乎已失效,请考虑:https://clojure .org/dev/contrib_howto#_coding_guidelines
针对您的具体观点:
You might want to look at the Clojure library coding standards on the developer Wiki - this is probably the most comprehensive list that I've seen.
Update: link above seems to be dead, consider instead: https://clojure.org/dev/contrib_howto#_coding_guidelines
To your specific points:
您可能需要查看这份非官方风格指南。
You might want to take a look at this non official style guide.
有一些有趣的Stuart Sierra 编写的命名指南这表明:
age
而不是calculate-age
)create-
用于构造,get-
用于检索),保留对可变引用的 bangswap!
更改。send-message
而不是message
)connection< /code> 而不是
->connection
),除非输入类型必须是显式的 (input-type->output-type
)products/price
而不是products/product-price
)并防止 let 绑定-fn
后缀There are some interesting guidelines on naming written by Stuart Sierra which suggest that:
age
instead ofcalculate-age
)create-
for constructing andget-
for retrieving), reserving the bangswap!
changes to mutable references.send-message
instead ofmessage
)connection
instead of->connection
) except when the input type must be explicit (input-type->output-type
)products/price
instead ofproducts/product-price
) and prevent local clashes in let bindings-fn
suffix在评论中记录了一组有趣的命名约定
陶恩索在他的
Encore 库。
他建议使用
!
来表示副作用,使用?
来表示布尔值,$
用于昂贵的操作,_
作为可取消的操作,*
用于宏;加上一些其他组合。There is an interesting set of naming conventions documented in a comment by
Taoensso in his
Encore library.
He proposes names using
!
for side-effects,?
for booleans,$
for expensive operations,_
as dereffable,*
for macros; plus a few other combos.即使您没有明确要求,我也会解释我所看到的协议命名约定。
通常,名称以大写“I”开头,然后其余部分为驼峰式大小写,其中每个单词的第一个字母大写,其余部分小写。例如,我想为火箭飞船定义一个协议,我会使用名称 IRocketShip
我还看到使用“A”而不是“I”,可能代表“抽象”一词。
Even though you didn't ask for it explicitly, I'll explain what I've seen for protocol naming conventions.
Typically, the name starts with an uppercase "I" and then the rest is camel case, where the first letter of each word is capitalized, and the rest is lower case. For example, I want to define a protocol for rocket ships, I'd use the name IRocketShip
I've also seen 'A' instead of 'I' used, probably to represent the word 'abstract'.