Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
article

Design and evaluation of C++ open multi-methods

Published: 01 July 2010 Publication History

Abstract

Multiple dispatch-the selection of a function to be invoked based on the dynamic type of two or more arguments-is a solution to several classical problems in object-oriented programming. Open multi-methods generalize multiple dispatch towards open-class extensions, which improve separation of concerns and provisions for retroactive design. We present the rationale, design, implementation, performance, programming guidelines, and experiences of working with a language feature, called open multi-methods, for C++. Our open multi-methods support both repeated and virtual inheritance. Our call resolution rules generalize both virtual function dispatch and overload resolution semantics. After using all information from argument types, these rules can resolve further ambiguities by using covariant return types. Care was taken to integrate open multi-methods with existing C++ language features and rules. We describe a model implementation and compare its performance and space requirements to existing open multi-method extensions and work-around techniques for C++. Compared to these techniques, our approach is simpler to use, catches more user mistakes, and resolves more ambiguities through link-time analysis, is comparable in memory usage, and runs significantly faster. In particular, the runtime cost of calling an open multi-method is constant and less than the cost of a double dispatch (two virtual function calls). Finally, we provide a sketch of a design for open multi-methods in the presence of dynamic loading and linking of libraries.

References

[1]
Agrawal, R., Demichiel, L.G. and Lindsay, B.G., Static type checking of multi-methods. In: OOPSLA***91: Conference Proceedings on Object-oriented Programming Systems, Languages, and Applications, ACM, New York, NY, USA.
[2]
Alexandrescu, A., Modern C++ Design: Generic Programming and Design Patterns Applied. 2001. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA.
[3]
E. Allen, D. Chase, J. Hallett, V. Luchangco, J.-W. Maessen, S. Ryu, G.L. Steele Jr., S. Tobin-Hochstadt, The Fortress Language Specification, Tech. rep., version 1.0 (March 2008)
[4]
Allen, E., Hallett, J., Luchangco, V., Ryu, S., Guy, J. and Steele, L., Modular multiple dispatch with multiple inheritance. In: SAC***07: Proceedings of the 2007 ACM Symposium on Applied Computing, ACM, New York, NY, USA.
[5]
Amiel, E., Gruber, O. and Simon, E., Optimizing multi-method dispatch using compressed dispatch tables. In: OOPSLA***94: Proceedings of the Ninth Annual Conf. on Object-oriented Programming Systems, Language, and Applications, ACM Press, New York, NY, USA.
[6]
Arnold, K., Gosling, J. and Holmes, D., The Java Programming Language. 2005. 4th ed. Prentice Hall, PTR.
[7]
Austern, M.H., Generic Programming and the STL: Using and Extending the C++ Standard Template Library. 1998. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA.
[8]
Becker, P., The C++ Standard Library Extensions: A Tutorial and Reference. 2006. 1st ed. Addison-Wesley Professional, Boston, MA, USA.
[9]
P. Becker, Working Draft, Standard for Programming Language C++, Tech. Rep. N2857, JTC1/SC22/WG21 C++ Standards Committee (March 2009)
[10]
Bettini, L., Capecchi, S. and Venneri, B., Double Dispatch in C++. Software - Practice and Experience. v36 i6. 581-613.
[11]
Birtwistle, G.M., Dahl, O., Myhrhaug, B. and Nygaard, K., Simula BEGIN. 1973. Auerbach Press, Philadelphia.
[12]
D. Bonniot, B. Keller, F. Barber, The Nice user***s manual (2008). http://nice.sourceforge.net/manual.html
[13]
L. Bourdev, J. Järvi, Efficient run-time dispatching in generic programming with minimal code bloat, in: Workshop of Library-Centric Software Design at OOPSLA***06, Portland Oregon, 2006
[14]
Boyland, J. and Castagna, G., Parasitic methods: An implementation of multi-methods for Java. In: OOPSLA***97: Proceedings of the 12th ACM SIGPLAN Conf. on Object-oriented Programming, Systems, Languages, and Applications, ACM Press, New York, NY, USA.
[15]
Bruce, K., Cardelli, L., Castagna, G., Leavens, G.T. and Pierce, B., On binary methods. Theor. Pract. Object Syst. v1 i3. 221-242.
[16]
Chambers, C., Object-oriented multi-methods in Cecil. In: ECOOP***92: Proceedings of the European Conf. on Object-oriented Programming, Springer-Verlag, London, UK.
[17]
C. Chambers, The Cecil language: Specification and rationale. 3.2, Tech. rep. (2004)
[18]
C. Chambers, The Diesel Language, specification and rationale (2006). http://www.cs.washington.edu/research/projects/cecil/www/Release/doc-diesel-lang/diesel-spec.pdf
[19]
Chambers, C. and Chen, W., Efficient multiple and predicated dispatching. In: OOPSLA***99: Proceedings of the 14th ACM SIGPLAN Conference on Object-oriented Programming, Systems, Languages, and Applications, ACM Press, New York, NY, USA.
[20]
Clifton, C., Leavens, G.T., Chambers, C. and Millstein, T., MultiJava: Modular open classes and symmetric multiple dispatch for Java. In: OOPSLA***00: Proceedings of the 15th ACM SIGPLAN Conf. on Object-oriented Programming, Systems, Languages, and Applications, ACM Press, New York, NY, USA.
[21]
Clifton, C., Millstein, T., Leavens, G.T. and Chambers, C., MultiJava: Design rationale, compiler implementation, and applications. ACM Trans. Program. Lang. Syst. v28 i3. 517-575.
[22]
codesourcery.com, The Itanium C++ ABI, Tech. rep. (2001)
[23]
Cormen, T.H., Leiserson, C.E., Rivest, R.L. and Stein, C., Introduction to Algorithms. 2001. MIT Press, Cambridge, MA, USA.
[24]
Edison Design Group, C++ Front End, http://www.edg.com/ (July 2008)
[25]
C.B. Flynn, D. Wonnacott, Reconciling encapsulation and dynamic dispatch via accessory functions, Tech. Rep. 387 (1999)
[26]
B. Foote, R. E. Johnson, J. Noble, Efficient multimethods in a single dispatch language, in: Proceedings of the European Conference on Object-Oriented Programming, Glasgow, Scotland, July
[27]
C. Frost, T. Millstein, Modularly typesafe interface dispatch in JPred, in: 2006 International Workshop on Foundations and Development of Object-oriented Languages, FOOL/WOOD***07, Charleston, SC, USA, 2006
[28]
Gamma, E., Helm, R., Johnson, R. and Vlissides, J., Design Patterns: Elements of Reusable Object-oriented Software. 1995. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA.
[29]
Gibbs, M. and Stroustrup, B., Fast dynamic casting. Softw. Pract. Exper. v36 i2. 139-156.
[30]
Goldberg, A. and Robson, D., Smalltalk-80: The Language and its Implementation. 1983. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA.
[31]
Gregor, D., Järvi, J., Siek, J., Stroustrup, B., Dos Reis, G. and Lumsdaine, A., Concepts: linguistic support for generic programming in C++. In: OOPSLA***06: Proceedings of the 21st Annual ACM SIGPLAN Conference on Object-oriented Programming Systems, Languages, and Applications, ACM Press, New York, NY, USA.
[32]
G. Greif, Chinese Dispatch***Unpublished notes for a talk, Dylan Hackers Conference, Berlin (July 2002). http://www.opendylan.org/cgi-bin/viewcvs.cgi/trunk/www/papers/ChineseDispatch.lout?rev=8014&view=markup
[33]
International Standardization Organization, ISO/IEC 10918-1:1994: Information technology***- Digital compression and coding of continuous-tone still images: Requirements and guidelines, pub-ISO, pub-ISO:adr, 1994
[34]
ISO/IEC 14882 International Standard, Programming languages: C++, American National Standards Institute, 1998
[35]
Järvi, J., Gregor, D., Willcock, J., Lumsdaine, A. and Siek, J., Algorithm specialization in generic programming: Challenges of constrained generics in C++. In: PLDI***06: Proceedings of the 2006 ACM SIGPLAN Conference on Programming Language Design and Implementation, ACM, New York, NY, USA.
[36]
Liskov, B., Keynote address - data abstraction and hierarchy. In: OOPSLA***87: Addendum to the Proceedings on Object-oriented Programming Systems, Languages and Applications (Addendum), ACM Press, New York, NY, USA.
[37]
L. Martin, Joint Strike Fighter, Air Vehicle, C++ Coding Standard, Lockheed Martin, 2005
[38]
Meyer, B., Eiffel: The Language. 1992. Prentice-Hall, Inc., Upper Saddle River, NJ, USA.
[39]
Millstein, T. and Chambers, C., Modular statically typed multimethods. Information and Computation. v175 i1. 76-118.
[40]
Millstein, T., Reay, M. and Chambers, C., Relaxed MultiJava: Balancing extensibility and modular typechecking. In: OOPSLA***03: Proceedings of the 18th Annual ACM SIGPLAN Conf. on Object-oriented Programing, Systems, Languages, and Applications, ACM Press, New York, NY, USA.
[41]
Millstein, T.D. and Chambers, C., Modular Statically Typed Multimethods. In: LNCS, vol. 1628. Springer-Verlag, London, UK.
[42]
Muschevici, R., Potanin, A., Tempero, E. and Noble, J., Multiple dispatch in practice. In: OOPSLA***08: Proceedings of the 23rd ACM SIGPLAN Conference on Object Oriented Programming Systems Languages and Applications, ACM, New York, NY, USA.
[43]
E. Panizzi, B. Pastorelli, Multimethods and separate static typechecking in a language with C++-like object model, The Computing Research Repository (CoRR) cs.PL/0005033
[44]
P. Pirkelbauer, S. Parent, M. Marcus, B. Stroustrup, Dynamic algorithm selection for runtime concepts, Science in Computer Programming, in press, (http://dx.doi.org/10.1016/j.scico.2009.04.002)
[45]
G.v. Rossum, The Python Language Reference Manual, Network Theory Ltd., 2003, Paperback
[46]
Schordan, M. and Quinlan, D., A source-to-source architecture for user-defined optimizations. In: LNCS, vol. 2789. Springer-Verlag.
[47]
Shalit, A., The Dylan Reference Manual. 1996. 2nd edition. Apple Press.
[48]
J. Smith, Draft proposal for adding Multimethods to C++., Tech. Rep. N1463 (2003)
[49]
Snyder, A., Encapsulation and inheritance in object-oriented programming languages. In: OOPSLA***86: Conference Proceedings on Object-oriented Programming Systems, Languages and Applications, ACM, New York, NY, USA.
[50]
Steele Jr, G.L., Common LISP: the Language. 1990. 2nd ed. Digital Press, Newton, MA, USA.
[51]
Stroustrup, B., The Design and Evolution of C++. 1994. ACM Press/Addison-Wesley Publishing Co., New York, NY, USA.
[52]
Stroustrup, B., The C++ Programming Language. 2000. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA.
[53]
Stroustrup, B. and Dos Reis, G., Supporting SELL for high-performance computing. In: LNCS, vol. 4339. Springer-Verlag.
[54]
Thomas, D. and Hunt, A., Programming Ruby: The Pragmatic Programmer***s Guide. 2000. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA.
[55]
Visser, J., Visitor combination and traversal control. In: OOPSLA***01: Proceedings of the 16th ACM SIGPLAN Conference on Object Oriented Programming, Systems, Languages, and Applications, ACM Press, New York, NY, USA.
[56]
Wasserrab, D., Nipkow, T., Snelting, G. and Tip, F., An operational semantics and type safety proof for multiple inheritance in C++. In: OOPSLA***06: Proceedings of the 21st Annual ACM SIGPLAN Conference on Object-oriented Programming Systems, Languages, and Applications, ACM Press, New York, NY, USA.
[57]
D. Wonnacott, Using accessory functions to generalize dynamic dispatch in single-dispatch object-oriented languages, in: COOTS***01: 6th USENIX Conference on Object-Oriented Technologies and Systems, San Antonio, TX, USENIX, 2001
[58]
Wöß, A., Löberbauer, M. and Mössenböck, H., LL(1) conflict resolution in a recursive descent compiler generator. In: LNCS, vol. 2789. Springer-Verlag.
[59]
www.boost.org, The Boost C++ Libraries, retrieved on July 4th, 2008
[60]
www.fourcc.org, Video codec and pixel format definitions, retrieved on February 20th, 2007

Cited By

View all

Recommendations

Reviews

Susan Shepherd Ferebee

The fact that Bjarne Stroustrup, the creator of C++, is one of the authors suggests that this paper on the C++ open multi-methods approach has validity. The authors ensure that the new approach supports C++ call-resolution semantics. Additionally, the work includes the changes to the C++ compiler, which are required for implementation. The paper addresses how object-oriented languages determine the method to invoke using a single runtime parameter. However, situations exist when the choice of function/method relies on two or more parameters. Additionally, these methods must be declared within class definitions, and programmers who design classes do not usually have enough information regarding the program's future use to address all issues that might arise at runtime. The authors believe that by separating classes and operations, static or dynamic dispatch can be chosen for each parameter at runtime. The authors discuss the following: Open-methods programming styles; Their function call for open methods and ambiguity resolution; Open methods in relation to other language characteristics; Required C++ compiler changes and extensions to the IA-64 object model; Other techniques that support multi-methods for C++; and Open multi-methods and the visitor pattern. The results show that the authors' open multi-methods approach is a significant improvement over existing techniques. Furthermore, the open multi-methods approach is only 16 percent slower than a current single dispatch approach. Open multi-methods can be applied to both hard real-time systems and embedded systems. Online Computing Reviews Service

Access critical reviews of Computing literature here

Become a reviewer for Computing Reviews.

Comments

Information & Contributors

Information

Published In

cover image Science of Computer Programming
Science of Computer Programming  Volume 75, Issue 7
July, 2010
197 pages

Publisher

Elsevier North-Holland, Inc.

United States

Publication History

Published: 01 July 2010

Author Tags

  1. Augmenting method problem
  2. Binary method problem
  3. C++
  4. Generic programming
  5. Multi-methods
  6. Multiple dispatch
  7. Object-oriented programming
  8. Open-methods

Qualifiers

  • Article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)0
  • Downloads (Last 6 weeks)0
Reflects downloads up to 26 Jan 2025

Other Metrics

Citations

Cited By

View all

View Options

View options

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media