arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 1708.01679cs.PL
收藏

动态类型语言中的作用域扩展方法

Scoped Extension Methods in Dynamically-Typed Languages

Guillermo Polito, Camille Teruel, Stéphane Ducasse, Luc Fabresse

摘要:

上下文扩展方法是在其宿主类的包之外的包中声明的方法。由于扩展方法,开发人员可以适应他们不拥有的类的需求:向核心类添加方法是一个典型的用例。这对于调整软件特别有用,因此可以提高可重用性。查询在大多数动态类型语言中,扩展方法是全局可见的。由于任何开发人员都可以为任何类定义扩展方法,因此会发生命名冲突:如果两个开发人员在同一个类中定义了具有相同签名的扩展方法,则只有一个扩展方法可见并覆盖另一个。类似地,如果两个开发人员在类层次结构中各自定义了一个同名的扩展方法,则其中一个将重写另一个。为了避免这种“意外覆盖”,一些动态类型语言将扩展方法的可见性限制在特定的范围内。然而,它们的语义还没有得到充分的描述和比较。此外,这些解决方案通常依赖于专用且缓慢的方法查找算法来解决运行时的冲突。Approach.在本文中,我们给出了Ruby精化、Groovy类别、Classbox和Method Shelter的底层模型的形式化,这些模型是动态类型语言中的范围扩展方法解决方案。知识我们的正式框架使我们能够客观地比较和分析所研究的解决方案和其他不同的方法,如MultiJava的缺点。此外,语言设计者可以使用我们的正式框架来确定哪种机制具有较少的“意外覆盖”风险。接地。我们的比较和分析现有的解决方案是接地,因为它是基于指称语义形式化。重要性扩展方法广泛用于支持它们的程序设计语言中,特别是动态类型语言,如Pharo,Ruby或Python。然而,如果没有精心设计的机制,此功能可能会导致潜在的隐藏错误,或者可以自愿用于访问受保护的操作,违反封装或破坏基本不变式。

英文摘要:

Context. An extension method is a method declared in a package other than the package of its host class. Thanks to extension methods, developers can adapt to their needs classes they do not own: adding methods to core classes is a typical use case. This is particularly useful for adapting software and therefore to increase reusability. Inquiry. In most dynamically-typed languages, extension methods are globally visible. Because any developer can define extension methods for any class, naming conflicts occur: if two developers define an extension method with the same signature in the same class, only one extension method is visible and overwrites the other. Similarly, if two developers each define an extension method with the same name in a class hierarchy, one overrides the other. To avoid such "accidental overrides", some dynamically-typed languages limit the visibility of an extension method to a particular scope. However, their semantics have not been fully described and compared. In addition, these solutions typically rely on a dedicated and slow method lookup algorithm to resolve conflicts at runtime. Approach. In this article, we present a formalization of the underlying models of Ruby refinements, Groovy categories, Classboxes, and Method Shelters that are scoping extension method solutions in dynamically-typed languages. Knowledge. Our formal framework allows us to objectively compare and analyze the shortcomings of the studied solutions and other different approaches such as MultiJava. In addition, language designers can use our formal framework to determine which mechanism has less risk of "accidental overrides". Grounding. Our comparison and analysis of existing solutions is grounded because it is based on denotational semantics formalizations. Importance. Extension methods are widely used in programming languages that support them, especially dynamically-typed languages such as Pharo, Ruby or Python. However, without a carefully designed mechanism, this feature can cause insidious hidden bugs or can be voluntarily used to gain access to protected operations, violate encapsulation or break fundamental invariants.

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

↑