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.
Supplemental Material
Available for Download
The auxiliary material provides the artifact supporting paper "Scrap Your Boilerplate with Object Algebras". Source code and some instructions of using the library are available in the compressed file. URL to GitHub repository: https://github.com/JasonCHU/SYBwithOA
- 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 Scholar
Digital Library
- G. M. Bierman, E. Meijer, and W. Schulte. The essence of data access in comega. In ECOOP, 2005. Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- B. Chadwick and K. Lieberherr. Weaving generic programming and traversal performance. In AOSD’10, 2010. Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- M. Gouseti, C. Peters, and T. v. d. Storm. Extensible language implementation with Object Algebras (short paper). In GPCE’14, 2014. Google Scholar
Digital Library
- J. Hannemann and G. Kiczales. Design pattern implementation in Java and aspectJ. In OOPSLA ’02, 2002. Google Scholar
Digital Library
- R. Lammel and S. P. Jones. Scrap your boilerplate: A practical design pattern for generic programming. In TLDI’03, 2003. Google Scholar
Digital Library
- R. Lämmel and S. P. Jones. Scrap more boilerplate: Reflection, zips, and generalised casts. In ICFP ’04, 2004.Google Scholar
Digital Library
- R. Lämmel and S. P. Jones. Scrap your boilerplate with class: Extensible generic functions. In ICFP ’05, 2005.Google Scholar
Digital Library
- R. Lämmel and J. Visser. Typed combinators for generic traversal. In Practical Aspects of Declarative Languages, pages 137–154. Springer, 2002. Google Scholar
Digital Library
- 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 Scholar
- R. Lämmel, E. Visser, and J. Visser. Strategic programming meets adaptive programming. In AOSD ’03, 2003.Google Scholar
Digital Library
- K. J. Lieberherr. Adaptive Object Oriented Software: The Demeter Method with Propagation Patterns. PWS Publishing, 1996. Google Scholar
Digital Library
- M. E. Nordberg. Variations on the visitor pattern, 1996.Google Scholar
- B. C. d. S. Oliveira and W. R. Cook. Extensibility for the masses, practical extensibility with object algebras. In ECOOP ’12, 2012. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- D. Orleans and K. J. Lieberherr. DJ: Dynamic adaptive programming in Java. In Reflection 2001. Springer-Verlag, 2001.Google Scholar
- J. Palsberg and C. B. Jay. The essence of the visitor pattern. In COMPSAC’98, 1998. Google Scholar
Digital Library
- T. Rendel, J. I. Brachthäuser, and K. Ostermann. From object algebras to attribute grammars. In OOPSLA ’14, 2014. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- E. Visser and Z.-e.-A. Benaissa. A core language for rewriting. Electronic Notes in Theoretical Computer Science, 15: 422–441, 1998.Google Scholar
Cross Ref
- E. Visser, Z.-e.-A. Benaissa, and A. Tolmach. Building program optimizers with rewriting strategies. In ICFP’98, 1998. Google Scholar
Digital Library
- J. Visser. Visitor combination and traversal control. In OOPSLA ’01, 2001. Google Scholar
Digital Library
- P. Wadler. The Expression Problem. Email, Nov. 1998.Google Scholar
- Discussion on the Java Genericity mailing list.Google Scholar
- P. Wadler and S. Blott. How to make ad-hoc polymorphism less ad hoc. In POPL ’89, 1989. Google Scholar
Digital Library
Index Terms
Scrap your boilerplate with object algebras
Recommendations
Scrap your boilerplate with object algebras
OOPSLA 2015: Proceedings of the 2015 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and ApplicationsTraversing 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 ...
Scrap your boilerplate: prologically!
PPDP '09: Proceedings of the 11th ACM SIGPLAN conference on Principles and practice of declarative programming"Scrap Your Boilerplate" (SYB) is an established style of generic functional programming. The present paper reconstructs SYB within the Prolog language with the help of the univ operator and higher-order logic programming techniques. We pay attention to ...
Scrap more boilerplate: reflection, zips, and generalised casts
ICFP '04: Proceedings of the ninth ACM SIGPLAN international conference on Functional programmingWriting boilerplate code is a royal pain. Generic programming promises to alleviate this pain by allowing the programmer to write a generic "recipe" for boilerplate code, and use that recipe in many places. In earlier work we introduced the "Scrap your ...






Comments