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


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

查看所有标签

猜你喜欢:

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

人工智能的未来

人工智能的未来

Jeff Hawkins、Sandra Blakeslee / 贺俊杰、李若子、杨倩 / 陕西科学技术出版社 / 2006.1 / 18.5

陕西科技出版社最新引进美国图书《人工智能的未来》(On Intelligence)一书,是由杰夫•霍金斯,一位在硅谷极其成功、受人尊敬的计算机工程师、企业家与桑德拉•布拉克斯莉,《纽约日报》的栏目作家共同撰写。本书对人类大脑皮层所具有的知觉、认识、行为和智能功能新理论提出了新的理论构想。这一理论的独到之处在于对大脑皮层的现行认识提出了新的观点,对大脑的工作原理,即霍金斯称之为“真正智能”而非计算机......一起来看看 《人工智能的未来》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

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

在线压缩/解压 CSS 代码

MD5 加密
MD5 加密

MD5 加密工具