skip to main content
research-article
Free Access

Contracts for First-Class Classes

Published:01 November 2013Publication History
Skip Abstract Section

Abstract

First-class classes enable programmers to abstract over patterns in the class hierarchy and to experiment with new forms of object-oriented programming such as mixins and traits. This increase in expressive power calls for tools to control the complexity of the software architecture. A contract system is one possible tool that has seen much use in object-oriented programming languages, but existing contract systems cannot cope with first-class classes. On the one hand, the typical contract language deals only with plain values such as numbers, while classes are higher-order values. On the other hand, contract specifications are usually contained within class definitions, while classes as values call for a separate contract language.

This article presents the design and implementation of a contract system for first-class classes as well as a two-pronged evaluation. The first one states and proves a “blame correctness” theorem for a model of our language. The theorem shows that when the contract system assigns blame to a component for a contract violation, the component is indeed responsible for providing the nonconforming value. The second part, consisting of benchmarks and case studies, demonstrates the need for the rich contract language and validates that our implementation approach is performant with respect to time.

References

  1. Eric Allen, Jonathan Bannet, and Robert Cartwright. 2003. A first-class approach to genericity. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’03). 96--114. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Eric Allen, David Chase, Joe Hallett, Victor Luchangco, Jan-Willem Maessen, Sukyoung Ryu, Guy L. Steele Jr., and Sam Tobin-Hochstadt. 2008. The Fortress Language Specification Version 1.0. Sun Microsystems.Google ScholarGoogle Scholar
  3. Davide Ancona, Giovanni Lagorio, and Elena Zucca. 2003. Jam---Designing a Java extension with mixins. ACM Trans. Program. Lang. Syst. 25, 5, 641--712. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Thomas H. Austin, Tim Disney, and Cormac Flanagan. 2010. Virtual values for language extension. Tech. rep. UCSC-SOE-10-25. University of California, Santa Cruz.Google ScholarGoogle Scholar
  5. Mike Barnett, K. Rustan M. Leino, and Wolfram Schulte. 2004. The spec# programming system: An overview. In Proceedings of the International Conference on Construction and Analysis of Safe, Secure and Interoperable Smart Devices (CASSIS’04). Lecture Notes in Computer Science, vol. 3362, Springer, 49--69. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Detlef Bartetzko, Clemens Fischer, Michael Moller, and Heikewehrheim. 2001. Jass---Java with assertions. Electron. Not. Theor. Comput. Sci. 55, 2, 103--117.Google ScholarGoogle ScholarCross RefCross Ref
  7. Gilad Bracha. 1992. The programming language jigsaw: Mixins, modularity, and multiple inheritance. Ph.D. dissertation. University of Utah. http://www.cs.utah.edu/dept/techreports/docs/ncstrl.utah_cs/UUCS-92-007/UUCS-92-007.pdf. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Gilad Bracha and William Cook. 1990. Mixin-based inheritance. In Proceedings of the European Conference on Object-Oriented Programming and the Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA/ECOOP’90). 303--311. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Gilad Bracha and David Ungar. 2004. Mirrors: Design principles for meta-level facilities of object-oriented programming languages. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’04). 331--344. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Luca Cardelli and John C. Mitchell. 1991. Operations on records. Math. Struct. Comput. Sci. 1, 3--48.Google ScholarGoogle ScholarCross RefCross Ref
  11. Manuela Carrillo-Castellon, Jesus Garcia-Molina, Ernesto Pimentel, and Israel Repiso. 1996. Design by contract in smalltalk. J. Object-Oriented Program. 7, 9, 23--28.Google ScholarGoogle Scholar
  12. Christos Dimoulas and Matthias Felleisen. 2011. On contract satisfaction in a higher-order world. ACM Trans. Program. Lang. Syst. 33, 5, 16:1--16:29. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Christos Dimoulas, Robert B. Findler, Cormac Flanagan, and Matthias Felleisen. 2011. Correct blame for contracts: No more scapegoating. In Proceedings of the Symposium on Principles of Programming Languages. 215--226. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Dominic Duggan and Ching-Ching Techaubol. 2001. Modular mixin-based inheritance for application frameworks. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’01). 223--240. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Erik Ernst. 1999. gbeta---A language with virtual attributes, block structure, and propagating, dynamic inheritance. Ph.D. dissertation. University of Aarhus, Arhus, Denmark. http://ojs.statsbiblioteket.dk/index.php/daimipb/article/download/7654/6510.Google ScholarGoogle Scholar
  16. Matthias Felleisen. 1991. On the expressive power of programming languages. Sci. Comput. Program. 17, 1--3, 35--75. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Matthias Felleisen, Robert Bruce Findler, and Matthew Flatt. 2009. Semantics Engineering with PLT Redex. MIT Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Robert Bruce Findler and Matthias Blume. 2006. Contracts as pairs of projections. In Proceedings of the International Symposium on Functional and Logic Programming (FLOPS’06). Lecture Notes in Computer Science, vol. 3945, Springer, 226--241. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Robert Bruce Findler, John Clements, Cormac Flanagan, Matthew Flatt, Shriram Krishnamurthi, Paul Steckler, and Matthias Felleisen. 2002. DrScheme: A programming environment for scheme. J. Funct. Program. 12, 2, 159--182. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Robert Bruce Findler and Matthias Felleisen. 2001. Contract soundness for object-oriented languages. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’01). 1--15. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Robert Bruce Findler and Matthias Felleisen. 2002. Contracts for higher-order functions. In Proceedings of the International Conference on Functional Programming. 48--59. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Kathleen Fisher and John Reppy. 2004. A typed calculus of traits. In Proceedings of the Workshop on Foundations of Object-Oriented Languages.Google ScholarGoogle Scholar
  23. David Flanagan and Yukihiro Matsumoto. 2008. The Ruby Programming Language. O’Reilly. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Matthew Flatt and PLT. 2010. Reference: Racket. Tech. rep. PLT-TR-2010-1. PLT Inc. http://racket-lang.org/tr1/.Google ScholarGoogle Scholar
  25. Matthew Flatt, Shriram Krishnamurthi, and Matthias Felleisen. 1998. Classes and mixins. In Proceedings of the Symposium on Principles of Programming Languages. 171--183. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Matthew Flatt, Robert Bruce Findler, and Matthias Felleisen. 2006. Scheme with classes, mixins, and traits. In Proceedings of the Asian Symposium on Programming Languages and Systems. Lecture Notes in Computer Science, vol. 4279, Springer, 270--289. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Benedict R. Gaster and Mark P. Jones. 1996. A polymorphic type system for extensible records and variants. Tech. rep. NOTTCS-TR-96-3. University of Nottingham.Google ScholarGoogle Scholar
  28. Adele Goldberg and David Robinson. 1983. Smalltalk-80: The Language and its Implementation. Addison-Wesley. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. David S. Goldberg, Robert Bruce Findler, and Matthew Flatt. 2004. Super and inner---Together at last! In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’04). 116--129. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Benedict Gomes, David Stoutamire, Boris Vaysman, and Holger Klawitter. 1996. A language manual for sather 1.1. http://www1.icsi.berkeley.edu/_sather/Documentation/LanguageDescription/Descript.pdf.gz.Google ScholarGoogle Scholar
  31. Kathryn E. Gray. 2008. Safe cross-language inheritance. In Proceedings of the European Conference on Object-Oriented Programming (ECOOP’08). Lecture Notes in Computer Science, vol. 5142, Springer, 52--75. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Kathryn E. Gray. 2010. Interoperability in a scripted world: Putting inheritance and prototypes together. In Proceedings of the Workshop on Foundations of Object-Oriented Languages.Google ScholarGoogle Scholar
  33. Kathryn E. Gray, Robert Bruce Findler, and Matthew Flatt. 2005. Fine-grained interoperability through contracts and mirrors. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’04). 231--245. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Robert Harper and Benjamin Pierce. 1991. A records calculus based on symmetric concatenation. In Proceedings of the Symposium on Principles of Programming Languages. 131--142. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Murat Karaorman, Urs Holzle, and John Bruno. 1999. jContractor: A reflective java library to support design by contract. In Proceedings of the International Conference on Meta-Level Architectures and Reflection (Reflection’99). Lecture Notes in Computer Science, vol. 1616, Springer, 175--196. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Michael Kolling and John Rosenberg. 1997. Blue: Language specification, version 0.94. http://www.sd.monash.edu.au/blue/.Google ScholarGoogle Scholar
  37. Reto Kramer. 1998. iContract: The java design by contract tool. In Proceedings of the Conference on Technology of Object-Oriented Languages and Systems. 295. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. John Lamping. 1993. Typing the specialization interface. In Proceedings of the Annual Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’93). 201--214. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Butler W. Lampson, James J. Horning, Ralph L. London, James G. Mitchell, and Gerald J. Popek. 1977. Report on the programming language euclid. SIGPLAN Not. 12, 2, 1--79. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Gary T. Leavens. 2006. JML’s rich, inherited specifications for behavioral subtypes. In Proceedings of the International Conference on Formal Engineering Methods (ICFEM’06). Lecture Notes in Computer Science, vol. 4260, Springer, 2--34. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Gary T. Leavens, Yoonsik Cheon, Curtis Clifton, Clyde Ruby, and David R. Cok. 2005. How the design of jml accommodates both runtime assertion checking and formal verification. Sci. Comput. Program. 55, 1--3, 185--208. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Ole Lehrmann Madsen, Birger Møller-Pedersen, and Kristen Nygaard. 1993. Object-Oriented Programming in the BETA Programming Language. Addison-Wesley Publishing, New York. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Barbara H. Liskov and Jeannette M. Wing. 1994. A behavioral notion of subtyping. ACM Trans. Program. Lang. Syst. 16, 6, 1811--1841. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. David C. Luckham and Friedrich W. Von Henke. 1985. An overview of anna, a specification language for ada. IEEE Softw. 2, 9--23. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Sean Mcdirmid, Matthew Flatt, and Wilson Hsieh. 2001. Jiazzi: New-age components for old-fashioned java. In Proceedings of the Annual Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’01). 211--222. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Bertrand Meyer. 1992a. Applying design by contract. IEEE Comput. 25, 10, 0--51. Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Bertrand Meyer. 1992b. Eiffel: The Language. Prentice Hall. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. David A. Moon. 1986. Object-oriented programming with flavors. In Proceedings of the Annual Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’86). 1--8. Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. David L. Parnas. 1972. On the criteria to be used in decomposing systems into modules. Comm. ACM 15, 12, 1053--1058. Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. Reinhold Plosch. 1997. Design by contract for python. In Proceedings of the IEEE Joint Asia Pacific Software Engineering Conference. 213--219. Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. Gordon D. Plotkin. 1977. LCF considered as a programming language. Theor. Comput. Sci. 5, 223--255.Google ScholarGoogle ScholarCross RefCross Ref
  52. Nathanael Scharli, Stephane Ducasse, Oscar Nierstrasz, and Andrew Black. 2003. Traits: Composable units of behavior. In Proceedings of the European Conference on Object-Oriented Programming (ECOOP’03). Lecture Notes in Computer Science, vol. 2743, Springer, 248--274.Google ScholarGoogle ScholarCross RefCross Ref
  53. Marco Servetto and Elena Zucca. 2010. MetaFJig: A meta-circular composition language for java-like classes. In Proceedings of the Annual Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’10). 464--483. Google ScholarGoogle ScholarDigital LibraryDigital Library
  54. T. Stephen Strickland and Matthias Felleisen. 2010a. Contracts for first-class classes. In Proceedings of the Dynamic Languages Symposium. 97--111. Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. T. Stephen Strickland and Matthias Felleisen. 2010b. Nested and dynamic contract boundaries. In Proceedings of the International Conference on Implementation and Application of Functional Languages (IFL’10). Lecture Notes in Computer Science, vol. 6041, Springer, 141--158. Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. T. Stephen Strickland, Sam Tobin-Hochstadt, Robert Bruce Findler, and Matthew Flatt. 2012. Chaperones and impersonators: Run-time support for reasonable interposition. In Proceedings of the Annual Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA’12). 943--962. Google ScholarGoogle ScholarDigital LibraryDigital Library
  57. Clemens Szyperski. 1997. Component Software. Addison-Wesley.Google ScholarGoogle Scholar
  58. Tom Van Cutsem and Mark Miller. 2010. Proxies: Design principles for robust object-oriented intercession apis. In Proceedings of the Dynamic Languages Symposium. 59--72. Google ScholarGoogle ScholarDigital LibraryDigital Library
  59. Mitchell Wand. 1994. Type inference for objects with instance variables and inheritance. In Theoretical Aspects of Object-Oriented Programming. MIT Press, 97--120. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Contracts for First-Class Classes

              Recommendations

              Reviews

              Nathan Carlson

              Contracts are formal and verifiable specifications that extend traditional type definitions by including preconditions, postconditions, invariants, acceptable inputs and outputs, and other behavioral specifications [1]. These class-level specifications can be used to verify both usage and behavior of software components at runtime. This paper details the concept of blame, which is implemented in the Racket language. When a contract violation occurs, blame enables the system to accurately indicate the guilty party in the failed transaction. First-class classes, or classes that are in themselves objects, enable new ways of composing class types without resorting to multiple inheritance. Some mainstream languages such as Java and C# do not support first-class classes, while Ruby and Python do. Contract systems are intended to specify conditions about values, and not about classes themselves, and their relationships. Contracts are specified at a class level. Contract systems do not normally support meta-definition of contracts or the sharing of contracts between different classes without duplication of code. The authors present details of an innovative contract-based approach for working with first-class classes. The proposed approach includes both the design and implementation of a contract system for first-class classes, including some theoretical foundations and a formal proof of a new "blame correctness" theorem. The paper includes a practical evaluation and validation of the approach. It is well-researched and thorough, but its value is limited by a focus on both design by contract and languages that support first-class classes. However, the paper should prove valuable to those with interests in these areas. Online Computing Reviews Service

              Access critical reviews of Computing literature here

              Become a reviewer for Computing Reviews.

              Comments

              Login options

              Check if you have access through your login credentials or your institution to get full access on this article.

              Sign in

              Full Access

              • Published in

                cover image ACM Transactions on Programming Languages and Systems
                ACM Transactions on Programming Languages and Systems  Volume 35, Issue 3
                November 2013
                156 pages
                ISSN:0164-0925
                EISSN:1558-4593
                DOI:10.1145/2542180
                Issue’s Table of Contents

                Copyright © 2013 ACM

                Publisher

                Association for Computing Machinery

                New York, NY, United States

                Publication History

                • Published: 1 November 2013
                • Accepted: 1 May 2013
                • Revised: 1 November 2012
                • Received: 1 March 2012
                Published in toplas Volume 35, Issue 3

                Permissions

                Request permissions about this article.

                Request Permissions

                Check for updates

                Qualifiers

                • research-article
                • Research
                • Refereed

              PDF Format

              View or Download as a PDF file.

              PDF

              eReader

              View online with eReader.

              eReader
              About Cookies On This Site

              We use cookies to ensure that we give you the best experience on our website.

              Learn more

              Got it!