何时何地在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


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

查看所有标签

猜你喜欢:

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

掘金大数据

掘金大数据

程新洲、朱常波、晁昆 / 机械工业出版社 / 2019-1 / 59.00元

在数据横向融合的时代,充分挖掘数据金矿及盘活数据资产,是企业发展和转型的关键所在。电信运营商以其数据特殊性,必将成为大数据领域的领航者、生力军。各行业的大数据从业者要如何从电信业的大数据中挖掘价值呢? 本书彻底揭开电信运营商数据的神秘面纱,系统介绍了大数据的发展历程,主要的数据挖掘方法,电信运营商在网络运行及业务运营方面的数据资源特征,基于用户、业务、网络、终端及内在联系的电信运营商大数据分......一起来看看 《掘金大数据》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

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

RGB HEX 互转工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具