内容简介:何时何地在Clojure代码中输入注释?显然,当性能计数.但是有没有什么规则可以在何时(仅当做Java Interop?)和哪里添加它们(函数定义参数)?http://stackoverflow.com/questions/2569069/when-and-where-do-you-put-type-annotations-in-clojure-code
何时何地在Clojure代码中输入注释?显然,当性能计数.但是有没有什么规则可以在何时(仅当做Java Interop?)和哪里添加它们(函数定义参数)?
我所知道的最重要的原因是性能,在clojure中的类型暗示消除了反射,这可能会降低性能,所以我将类型提示放在我所测量的功能中,使其性能至关重要.
在 clojure.org 的 java 互操作部分有一个 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
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- iOS 注释方法大全 代码块加快捷键注释
- 让 MyBatis Generator 用数据库注释作 Java 注释,并支持附加注解
- 请停止代码注释
- 体面编码之代码注释评论
- Spring 注解注入—@Qualifier 注释
- swagger注释API详细说明
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
计算机图形学原理及实践:C语言描述(原书第2版) (平装)
福利 / 唐泽圣 / 机械工业出版社 / 2004-3 / 95.0
《计算机图形学原理及实践:C语言描述(原书第2版)》:这是计算机图形学领域的一部经典之作,作者Fley、va Dam等是国际图形学界的著名学者、学术带头人,而且《计算机图形学原理及实践:C语言描述(原书第2版)》英文版自出版以来,一直是各国大学计算机图形学课程的主要教科书。来自清华大学、北京大学、中国科学院计算技术研究所、中国科学院软件研究所的多位图形学领域的专家和精英花费了大量的时间和精力进行翻......一起来看看 《计算机图形学原理及实践:C语言描述(原书第2版) (平装)》 这本书的介绍吧!
RGB转16进制工具
RGB HEX 互转工具
随机密码生成器
多种字符组合密码