arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1704.03095cs.PL
收藏

量化和解释Scala中的不变性

Quantifying and Explaining Immutability in Scala

Philipp Haller, Ludvig Axelsson

摘要:

函数式编程通常强调使用一流函数和不可变数据进行编程。不可变数据类型在分布式系统中启用了容错,并确保在消息传递并发性和其他应用程序中的进程隔离。然而,除了可重新分配和不可重新分配字段之间的区别之外,Scala的类型系统没有内置的类型定义不变性概念。因此,不变性在Scala中是“约定俗成的”,关于在真实Scala代码中使用不变性的统计数据是不存在的。本文报告了在几个大中型Scala开源代码库中使用不变性的实证研究结果,包括Scala的标准库和Akka actor框架。该研究调查了浅层和深层不变性,这是Scala中广泛使用的两种不变性形式。也许最有趣的是,对于被确定为可变的类型定义,解释了为什么浅不可变属性和深不可变属性都不成立;反过来,这些解释被汇总到统计数据中,以确定为什么类型定义是可变的而不是不可变的最常见的原因。

英文摘要:

Functional programming typically emphasizes programming with first-class functions and immutable data. Immutable data types enable fault tolerance in distributed systems, and ensure process isolation in message-passing concurrency, among other applications. However, beyond the distinction between reassignable and non-reassignable fields, Scala's type system does not have a built-in notion of immutability for type definitions. As a result, immutability is "by-convention" in Scala, and statistics about the use of immutability in real-world Scala code are non-existent. This paper reports on the results of an empirical study on the use of immutability in several medium-to-large Scala open-source code bases, including Scala's standard library and the Akka actor framework. The study investigates both shallow and deep immutability, two widely-used forms of immutability in Scala. Perhaps most interestingly, for type definitions determined to be mutable, explanations are provided for why neither the shallow nor the deep immutability property holds; in turn, these explanations are aggregated into statistics in order to determine the most common reasons for why type definitions are mutable rather than immutable.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑