有没有Clojure约定命名私有函数? [英] Is there a Clojure convention for naming private functions?

查看:83
本文介绍了有没有Clojure约定命名私有函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Clojure中定义一个私有函数时,我通常使用一个 - 前缀作为可视化指示符,该函数不能在我的命名空间之外使用,例如

When I define a private function in Clojure, I usually use a - prefix as a visual indicator that the function cannot be used outside of my namespace, e.g.

(defn- -name []
  (let [formatter (formatter "yyyy-MM-dd-HH-mm-ss-SSSS")]
    (format "fixjure-%s" (unparse formatter (now)))))


b $ b

但是,当使用 gen-class 时, - 前缀似乎也是公共方法的约定。 。

But the - prefix seems to also be a convention for public methods when using gen-class.

在Clojure社区中有 defn - '函数的任何通用约定,使用非前缀名?

Is there any generally accepted convention for defn-'d functions in the Clojure community, or should I simply use non-prefixed names?

似乎clojure.contrib中的许多代码(可能安静)使用正常的名称作为私有函数,所以也许这是最好的,但我真的很喜欢视觉指示器 - 也许我的C / Perl背景太强了! ;)

It seems that lots of code in clojure.contrib (may it rest in peace) uses normal names for private functions, so maybe that is best, but I really like the visual indicator--maybe my C / Perl background is just too strong! ;)

推荐答案

视觉指示器在没有内在概念的私有功能的语言中是普遍的。由于Clojure的 defn - 定义的函数在它们的命名空间之外是不可见的,因此不需要用一个丑陋的函数来前缀函数);

There's not a convention; the visual indicator is prevalent in languages with no built-in notion of private functions. Since Clojure's functions defined with defn- are not visible outside their namespace, there is no need to prefix functions with an uglifier ;)

所以做你所做的,但你应该可能想做只剩下的社区,只是命名他们正常!它会让你的生活更轻松。

So do what you but, but you should probably want to just do as the rest of community does and just name them normally! It'll make your life easier.

这篇关于有没有Clojure约定命名私有函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆