skip to main content
research-article

Scrap your boilerplate with object algebras

Published:23 October 2015Publication History
Skip Abstract Section

Abstract

Traversing complex Abstract Syntax Trees (ASTs) typically requires large amounts of tedious boilerplate code. For many operations most of the code simply walks the structure, and only a small portion of the code implements the functionality that motivated the traversal in the first place. This paper presents a type-safe Java framework called Shy that removes much of this boilerplate code. In Shy object algebras are used to describe complex and extensible AST structures. Using Java annotations Shy generates generic boilerplate code for various types of traversals. For a concrete traversal, users of Shy can then inherit from the generated code and override only the interesting cases. Consequently, the amount of code that users need to write is significantly smaller. Moreover, traversals using the Shy framework are also much more structure shy, becoming more adaptive to future changes or extensions to the AST structure. To prove the effectiveness of the approach, we applied Shy in the implementation of a domain-specific questionnaire language. Our results show that for a large number of traversals there was a significant reduction in the amount of user-defined code.

Skip Supplemental Material Section

Supplemental Material

References

  1. M. D. Adams and T. M. DuBuisson. Template your boilerplate: Using Template Haskell for efficient generic programming. In Proceedings of the 2012 ACM SIGPLAN Haskell symposium, Haskell ’12, pages 13–24, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. G. M. Bierman, E. Meijer, and W. Schulte. The essence of data access in comega. In ECOOP, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. P. Borovansk`y, C. Kirchner, H. Kirchner, P.-E. Moreau, and M. Vittek. ELAN: A logical framework based on computational systems. Electronic Notes in Theoretical Computer Science, 4:35–50, 1996.Google ScholarGoogle Scholar
  4. M. Bravenboer and E. Visser. Guiding visitors: Separating navigation from computation. Technical Report UU-CS- 2001-42, Institute of Information and Computing Sciences, Utrecht University, 2001.Google ScholarGoogle Scholar
  5. B. Chadwick and K. Lieberherr. Weaving generic programming and traversal performance. In AOSD’10, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. N. de Bruijn. Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem. Indagationes Mathematicae (Proceedings), 75(5):381–392, 1972.Google ScholarGoogle ScholarCross RefCross Ref
  7. S. Erdweg, T. van der Storm, M. Völter, M. Boersma, R. Bosman, W. R. Cook, A. Gerritsen, A. Hulshout, S. Kelly, A. Loh, et al. The state of the art in language workbenches. In Software Language Engineering. Springer, 2013.Google ScholarGoogle ScholarCross RefCross Ref
  8. E. Gamma, R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements of Reusable Object-oriented Software. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1995. ISBN 0-201-63361-2. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. M. Gouseti, C. Peters, and T. v. d. Storm. Extensible language implementation with Object Algebras (short paper). In GPCE’14, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. J. Hannemann and G. Kiczales. Design pattern implementation in Java and aspectJ. In OOPSLA ’02, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. R. Lammel and S. P. Jones. Scrap your boilerplate: A practical design pattern for generic programming. In TLDI’03, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. R. Lämmel and S. P. Jones. Scrap more boilerplate: Reflection, zips, and generalised casts. In ICFP ’04, 2004.Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. R. Lämmel and S. P. Jones. Scrap your boilerplate with class: Extensible generic functions. In ICFP ’05, 2005.Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. R. Lämmel and J. Visser. Typed combinators for generic traversal. In Practical Aspects of Declarative Languages, pages 137–154. Springer, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. R. Lämmel, J. Visser, and J. Kort. Dealing with large bananas. In J. Jeuring, editor, Workshop on Generic Programming, Ponte de Lima, July 2000. Technical Report UU-CS- 2000-19, Universiteit Utrecht.Google ScholarGoogle Scholar
  16. R. Lämmel, E. Visser, and J. Visser. Strategic programming meets adaptive programming. In AOSD ’03, 2003.Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. K. J. Lieberherr. Adaptive Object Oriented Software: The Demeter Method with Propagation Patterns. PWS Publishing, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. M. E. Nordberg. Variations on the visitor pattern, 1996.Google ScholarGoogle Scholar
  19. B. C. d. S. Oliveira and W. R. Cook. Extensibility for the masses, practical extensibility with object algebras. In ECOOP ’12, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. B. C. d. S. Oliveira, M. Wang, and J. Gibbons. The visitor pattern as a reusable, generic, type-safe component. In OOPSLA’08, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. B. C. d. S. Oliveira, T. van der Storm, A. Loh, and W. R. Cook. Feature-oriented programming with object algebras. In ECOOP ’13, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. D. Orleans and K. J. Lieberherr. DJ: Dynamic adaptive programming in Java. In Reflection 2001. Springer-Verlag, 2001.Google ScholarGoogle Scholar
  23. J. Palsberg and C. B. Jay. The essence of the visitor pattern. In COMPSAC’98, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. T. Rendel, J. I. Brachthäuser, and K. Ostermann. From object algebras to attribute grammars. In OOPSLA ’14, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. M. G. J. van den Brand, P. Klint, and J. J. Vinju. Term rewriting with traversal functions. ACM Trans. Softw. Eng. Methodol., 12(2):152–190, Apr. 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. E. Visser and Z.-e.-A. Benaissa. A core language for rewriting. Electronic Notes in Theoretical Computer Science, 15: 422–441, 1998.Google ScholarGoogle ScholarCross RefCross Ref
  27. E. Visser, Z.-e.-A. Benaissa, and A. Tolmach. Building program optimizers with rewriting strategies. In ICFP’98, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. J. Visser. Visitor combination and traversal control. In OOPSLA ’01, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. P. Wadler. The Expression Problem. Email, Nov. 1998.Google ScholarGoogle Scholar
  30. Discussion on the Java Genericity mailing list.Google ScholarGoogle Scholar
  31. P. Wadler and S. Blott. How to make ad-hoc polymorphism less ad hoc. In POPL ’89, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Scrap your boilerplate with object algebras

        Recommendations

        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 SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 50, Issue 10
          OOPSLA '15
          October 2015
          953 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/2858965
          • Editor:
          • Andy Gill
          Issue’s Table of Contents
          • cover image ACM Conferences
            OOPSLA 2015: Proceedings of the 2015 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications
            October 2015
            953 pages
            ISBN:9781450336895
            DOI:10.1145/2814270

          Copyright © 2015 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 23 October 2015

          Check for updates

          Qualifiers

          • research-article

        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!