Programming languages are embracing both functional and object-oriented paradigms. A key difference between the two paradigms is the way of achieving data abstraction. That is, how to organize data with associated operations. There are important tradeoffs between functional and object-oriented decomposition in terms of extensibility and expressiveness. Unfortunately, programmers are usually forced to select a particular decomposition style in the early stage of programming. Once the wrong design decision has been made, the price for switching to the other decomposition style could be rather high since pervasive manual refactoring is often needed. To address this issue, this paper presents a bidirectional transformation system between functional and object-oriented decomposition. We formalize the core of the system in the FOOD calculus, which captures the essence of functional and object-oriented decomposition. We prove that the transformation preserves the type and semantics of the original program. We further implement FOOD in Scala as a translation tool called Cook and conduct several case studies to demonstrate the applicability and effectiveness of Cook.
翻译:编程语言包含功能和面向目标的范式。 两种范式之间的一个关键区别是实现数据抽象的方式。 即如何组织相关操作的数据。 功能和面向目标的分解在可扩展性和表达性方面有着重要的平衡。 不幸的是,编程者通常被迫在编程的早期阶段选择特定的分解风格。 一旦作出错误的设计决定, 转换到其他分解样式的价格可能相当高, 因为通常需要普遍人工重构。 为了解决这个问题,本文展示了功能和面向目标的分解之间的双向转换系统。 我们正式确定该系统的核心在FOD的计算中, 记录了功能和面向目标的分解的本质。 我们证明, 转换保留了原始程序的类型和语义。 我们在Scala进一步使用FOD作为翻译工具, 称为Cook, 并进行了几项案例研究, 以证明库克的实用性和有效性。