何时何地在Clojure代码中输入注释?

栏目: 编程语言 · Clojure · 发布时间: 5年前

内容简介:何时何地在Clojure代码中输入注释?显然,当性能计数.但是有没有什么规则可以在何时(仅当做Java Interop?)和哪里添加它们(函数定义参数)?http://stackoverflow.com/questions/2569069/when-and-where-do-you-put-type-annotations-in-clojure-code

何时何地在Clojure代码中输入注释?显然,当性能计数.但是有没有什么规则可以在何时(仅当做Java Interop?)和哪里添加它们(函数定义参数)?

我所知道的最重要的原因是性能,在clojure中的类型暗示消除了反射,这可能会降低性能,所以我将类型提示放在我所测量的功能中,使其性能至关重要.

clojure.orgjava 互操作部分有一个 description .在这些评论中:

Clojure supports the use of type hints to assist the compiler in avoiding reflection in performance-critical areas of code. Normally, one should avoid the use of type hints until there is a known performance bottleneck.
…  Once a type hint has been placed on an identifier or expression, the compiler will try to resolve any calls to methods thereupon at compile time. In addition, the compiler will track the use of any return values and infer types for their use and so on, so very few hints are needed to get a fully compile-time resolved series of calls. Note that type hints are not needed for static members (or their return values!) as the compiler always has the type for statics.

您可以随时打开反射标志的警告,以查看正在调用反射的位置,因此,类型提示可能会有所帮助.

编辑:

关于你的问题“只为java互操作?” – 没有.即使在纯粹的clojure应用程序中,类型提示也很有用.反思放慢性能的问题是JVM上的一个生命的事实,是动态语言一般要处理的问题.

关于何种类型的提示,可以从clojure.org:

They can be placed on function parameters, let-bound names, var names (when defined), and expressions:

http://stackoverflow.com/questions/2569069/when-and-where-do-you-put-type-annotations-in-clojure-code


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

奔腾年代

奔腾年代

郭万盛 / 中信出版集团 / 2018-9-1 / 68.00

1994年4月20日,一条64K国际专线将中关村地区教育与科研示范网络与互联网连在了一起。中国,成为第77个全功能接入互联网的国家。 1995年,中国互联网正式开始商业化应用。浪潮开始! 这是一个波澜壮阔的年代,带给我们翻天覆地的变化。中国互联网25年发展史的全景展示、忠实梳理和记录。 在更宏观的角度审视互联网与中国的关系,人们将会发现,互联网革命给中国带来了重新崛起的时代机遇。......一起来看看 《奔腾年代》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具