Design Rationale, Compiler Implementation, and Applications Curtis Clifton Iowa State University

Design Rationale, Compiler Implementation, and Applications Curtis Clifton Iowa State University

Computer Science Technical Reports Computer Science 12-2004 MultiJava: Design Rationale, Compiler Implementation, and Applications Curtis Clifton Iowa State University Todd Millstein Iowa State University Gary T. Leavens Iowa State University Craig Chambers Iowa State University Follow this and additional works at: http://lib.dr.iastate.edu/cs_techreports Part of the Programming Languages and Compilers Commons Recommended Citation Clifton, Curtis; Millstein, Todd; Leavens, Gary T.; and Chambers, Craig, "MultiJava: Design Rationale, Compiler Implementation, and Applications" (2004). Computer Science Technical Reports. 326. http://lib.dr.iastate.edu/cs_techreports/326 This Article is brought to you for free and open access by the Computer Science at Iowa State University Digital Repository. It has been accepted for inclusion in Computer Science Technical Reports by an authorized administrator of Iowa State University Digital Repository. For more information, please contact [email protected]. MultiJava: Design Rationale, Compiler Implementation, and Applications Abstract MultiJava is a conservative extension of the Java programming language that adds symmetric multiple dispatch and open classes. Among other benefits, ultm iple dispatch provides a solution to the binary method problem. Open classes provide a solution to the extensibility problem of object-oriented programming languages, allowing the modular addition of both new types and new operations to an existing type hierarchy. This paper illustrates and motivates the design of MultiJava and describes its modular static typechecking and modular compilation strategies. Although MultiJava extends Java, the key ideas of the language design are applicable to other object-oriented languages, such as C# and C++, and even, with some modifications, to functional languages such as ML. This paper also discusses the variety of application domains in which MultiJava has been successfully used by others, including pervasive computing, graphical user interfaces, and compilers. MultiJava allows users to express desired programming idioms in a way that is declarative and supports static typechecking, in contrast to the tedious and type-unsafe workarounds required in Java. MultiJava also provides opportunities for new kinds of extensibility that are not easily available in Java. Keywords Open Classes, Open Objects, Extensible Classes, Extensible External Methods, External Methods, Multimethods, Method Families, Generic Functions, % so people searching on this term can find it Object- oriented Programming Languages, Single Dispatch, Multiple Dispatch, Encapsulation, Modularity, Static Typechecking, Subtyping, Inheritance, Java Language, MultiJava Language, Separate Compilation, Expression Problem, Binary Method Problem, Augmenting Method Problem Disciplines Programming Languages and Compilers This article is available at Iowa State University Digital Repository: http://lib.dr.iastate.edu/cs_techreports/326 MultiJava: Design Rationale, Compiler Implementation, and Applications Curtis Clifton, Todd Millstein, Gary T. Leavens, and Craig Chambers TR #04-01b December 2004 Revised version of TR #04-01, dated January 2004 and titled MultiJava: Design Rationale, Compiler Implementation, and User Experience Keywords: Open Classes, Open Objects, Extensible Classes, Extensible Exter- nal Methods, External Methods, Multimethods, Generic Functions, Object-oriented Programming Languages, Single Dispatch, Multiple Dispatch, Encapsulation, Mod- ularity, Static Typechecking, Subtyping, Inheritance, Java Language, MultiJava Language, Separate Compilation 2002 CR Categories: D.3.1 [Programming Techniques] Object-oriented Pro- gramming; D.3.2 [Programming Languages] Language Classifications — object- oriented languages; D.3.3 [Programming Languages] Language Constructs and Fea- tures — abstract data types, classes and objects, control structures, inheritance, modules, packages, patterns, procedures, functions and subroutines; D.3.4 [Pro- gramming Languages] Processors — compilers; D.3.m [Programming Languages] Miscellaneous — generic functions, multimethods, open classes. Copyright c 2004, Curtis Clifton, Todd Millstein, Gary T. Leavens, and Craig Chambers, Submitted for Publication. Department of Computer Science 226 Atanasoff Hall Iowa State University Ames, Iowa 50011-1040, USA MultiJava: Design Rationale, Compiler Implementation, and Applications CURTIS CLIFTON Iowa State University TODD MILLSTEIN University of California, Los Angeles GARY T. LEAVENS Iowa State University and CRAIG CHAMBERS University of Washington MultiJava is a conservative extension of the Java programming language that adds symmetric multiple dispatch and open classes. Among other benefits, multiple dispatch provides a solution to the binary method problem. Open classes provide a solution to the extensibility problem of object-oriented programming languages, allowing the modular addition of both new types and new operations to an existing type hierarchy. This paper illustrates and motivates the design of MultiJava and describes its modular static typechecking and modular compilation strategies. Although MultiJava extends Java, the key ideas of the language design are applicable to other object-oriented languages, such as C# and C++, and even, with some modifications, to functional languages such as ML. This paper also discusses the variety of application domains in which MultiJava has been suc- cessfully used by others, including pervasive computing, graphical user interfaces, and compilers. MultiJava allows users to express desired programming idioms in a way that is declarative and supports static typechecking, in contrast to the tedious and type-unsafe workarounds required in Java. MultiJava also provides opportunities for new kinds of extensibility that are not easily available in Java. Categories and Subject Descriptors: D.3.1 [Programming Techniques]: Object-oriented Pro- gramming; D.3.2 [Programming Languages]: Language Classifications—object-oriented lan- guages; D.3.3 [Programming Languages]: Language Constructs and Features—abstract data types; classes and objects; control structures; inheritance; modules, packages; patterns; pro- cedures, functions, and subroutines; D.3.4 [Programming Languages]: Processors—compil- ers; D.3.m [Programming Languages]: Miscellaneous—method families; multimethods; open classes General Terms: Languages, Design Additional Key Words and Phrases: Open Classes, Open Objects, Extensible Classes, Extensi- ble External Methods, External Methods, Multimethods, Method Families, Generic Functions, Object-oriented Programming Languages, Single Dispatch, Multiple Dispatch, Encapsulation, Modularity, Static Typechecking, Subtyping, Inheritance, Java Language, MultiJava Language, Separate Compilation, Expression Problem, Binary Method Problem, Augmenting Method Prob- lem 1. INTRODUCTION In this paper we describe the design and implementation of MultiJava [Clifton et al. 2000; Clifton 2001] and the ways in which the language has been used ACM Transactions on Programming Languages and Systems, Vol. V, No. N, December 2004, Pages 1–59. 2 · Curtis Clifton et al. by others [Millstein 2003]. MultiJava is a backward-compatible extension to the Java programming language [Gosling et al. 2000] that supports symmetric multiple dispatch and open classes. MultiJava is backward compatible with Java in two ways. First, existing Java programs are legal MultiJava programs and have the same meaning. Second, code using MultiJava’s new language features interoper- ates with existing Java source and bytecode. Our MultiJava compiler is available from www.multijava.org. 1.1 The Problem We begin by describing two problems that arise with mainstream object-oriented programming languages like C++ and Java [Stroustrup 1997; Arnold et al. 2000; Gosling et al. 2000]. These problems are examples of a general extensibilty problem that arises from not being able to dynamically dispatch on a class except by editing the class in place. 1.1.1 The Binary Method Problem. A well-known problem in mainstream object- oriented programming languages concerns expressing the behavior of methods when that behavior should vary with the dynamic types of more than one argument. Traditionally, the problem is considered in terms of binary methods, two-argument methods where the argument types should vary together. In the Shape class of Fig. 1, the method for calculating the intersection of two shapes—the receiver ob- ject this and the argument object s—is a binary method. Suppose that one wishes to create a class Rectangle as a subclass of Shape. When intersecting two rectan- gles, one can use a more efficient algorithm than for arbitrary shapes. We would like to implement this more efficient algorithm for rectangles, without having to modify existing code, in either the Shape class or its clients. Further, we would like to do this in a way that can be statically typechecked for safety. Unfortunately there is no straightforward way to do this, because mainstream object-oriented languages cannot safely use subtypes in the argument positions of overriding methods. Doing so would violate the standard restriction against covari- ant subtyping for function parameter types [Cardelli 1988]. Thus, such languages cannot easily specify overriding binary methods for cases where both the receiver and non-receiver arguments are subtypes of the original types. This difficulty in specifying specialized behavior for overriding binary methods is known as the binary method problem

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    62 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us