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

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

内容简介:何时何地在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


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

查看所有标签

猜你喜欢:

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

Netty实战

Netty实战

诺曼·毛瑞尔(Norman Maurer)、马文·艾伦·沃尔夫泰尔(Marvin Allen Wolfthal) / 何品 / 人民邮电出版社 / 2017-5-1 / 69.00

编辑推荐 - Netty之父”Trustin Lee作序推荐 - 阿里巴巴中间件高级技术专家为本书中文版作序推荐 - 系统而详细地介绍了Netty的各个方面并附带了即用型的优质示例 - 附带行业一线公司的案例研究 - 极实用的Netty技术书 无论是构建高性能的Web、游戏服务器、推送系统、RPC框架、消息中间件还是分布式大数据处理引擎,都离不开Nett......一起来看看 《Netty实战》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试