Addressing Common Crosscutting Problems with Arcum∗
Total Page:16
File Type:pdf, Size:1020Kb
Addressing Common Crosscutting Problems with Arcum∗ Macneil Shonle William G. Griswold Sorin Lerner Computer Science & Engineering, UC San Diego La Jolla, CA 92093-0404 {mshonle, wgg, lerner}@cs.ucsd.edu ABSTRACT 1. INTRODUCTION Crosscutting is an inherent part of software development and can Arcum is a framework for declaring and performing user-defined typically be managed through modularization: A module’s stable program checks and transformations, with the goal of increasing properties are defined in an interface while its likely-to-change automated refactoring opportunities for the user [21]. By using Ar- properties are encapsulated within the module [19]. The cross- cum, a programmer can view the implementation of a crosscutting cutting of the stable properties, such as class and method names, design idiom as a form of module. Arcum uses a declarative lan- can be mitigated with automated refactoring tools that allow, for guage to describe the idiom’s implementation, where descriptions example, the interface’s elements to be renamed [9, 18]. However, are composed of Arcum interface and Arcum option constructs. An often the crosscutting from design idioms (such as design patterns option describes one possible implementation of a crosscutting de- and coding styles) are so specific to the program’s domain that sign idiom, and a set of options are related to each other when they their crosscutting would not likely have been anticipated by the all implement the same Arcum interface. developers of an automated refactoring system. Arcum’s declarative language uses a Java-like syntax for first- The Arcum plug-in for Eclipse enables programmers to describe order logic predicate statements, including a special pattern nota- the implementation of a crosscutting design idiom as a set of syn- tion for expressing Java code. Like most declarative languages, tactic patterns and semantic constraints. Arcum can process dec- Arcum operates from a database of relations. Arcum’s database larations of related implementations and infer the refactoring steps contains relations associated with the program being analyzed, in- necessary to transform a program from using one implementation cluding relations like isA, hasMethod, and copiedTo, and with spe- to its alternatives. As a result, automating refactoring for domain- cial relations to cover Java syntax, such as method invocations, field specific crosscutting design idioms can be easy and practical. This references, and type declarations. paper presents a case study of how Arcum was used to mitigate This paper presents a case study of Arcum’s use on its own code- four classic software engineering problems that are exacerbated base, where we encountered a variety of classical software engi- by crosscutting: library migration, debugging, programmer-defined neering problems that are induced by crosscutting design idioms. semantic checking, and architectural enforcement. This paper extends our previous work [21] by demonstrating sev- eral plausible ways crosscutting manifests itself in real-life pro- grams, and how such crosscutting can be mitigated. Categories and Subject Descriptors The Arcum project is an Eclipse plug-in written in Java, which D.2.11 [Software Engineering]: Software Architectures— comprises of over 150 public classes and 19,000 lines of code. We Domain-specific architectures, languages, patterns chose the Arcum codebase in part because we are familiar with it and we believe it uses idioms that can be assisted with Arcum. We found that many of the software engineering problems en- General Terms countered were not specific to the particulars of the project, yet Languages, Design. also not general enough to be anticipated by tool developers or even the Java language designers. We believe there is a middle ground between problems so readily encountered they are addressed di- Keywords rectly by the language, and problems so rarely encountered that Refactoring, design patterns, aspect-oriented programming. you would only need to cope with them once. For our purposes, we refer to this middle ground as involving domain specific needs. The ∗ This work was supported in part by an Eclipse Innovation Award purpose of the case study is to demonstrate the frontier of possibil- from IBM and NSF Science of Design grant CCF-0613845. ity for an expert in the Arcum framework, leaving open for future user-studies to show how well a non-expert can employ Arcum for intermediate-level tasks. Each category of software engineering problem covered has a Permission to make digital or hard copies of all or part of this work for working example developed and tested against the codebase. The personal or classroom use is granted without fee provided that copies are first category covers problems related to code migration and the not made or distributed for profit or commercial advantage and that copies trade offs between making a program’s implementation more stan- bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific dardized or more project specific (Section 2). The second category permission and/or a fee. covers the process of debugging (Section 3) and the third category PASTE ’08 Atlanta, Georgia USA covers how needs specific to a domain differ from the general needs Copyright 2008 ACM 978-1-60558-382-2/08/11 ...$5.00. 01 interface IntegerBoxingOperation { 02 abstract boxing(Expr expr, Expr boxedValue) { 03 exists (DeclarationElement d) { 04 d == [Integer] && copiedTo(expr, d) 05 } 06 && isA(boxedValue, <int>) 07 } 08 } 09 10 option ImplicitBoxing implements IntegerBoxingOperation { 11 realize boxing(Expr expr, Expr boxedValue) { expr == [‘boxedValue] } 12 } 13 14 option ExplicitBoxing implements IntegerBoxingOperation { 15 realize boxing(Expr expr, Expr boxedValue) { expr == [new Integer(‘boxedValue)] } 16 } Figure 1: The ImplicitBoxing option matches all int expressions that get implicitly boxed into an instance of Integer. When this option is transformed into the ExplicitBoxing operation the Integer constructor is explicitly called. that a programming language covers (Section 4). The final category laration element.1 covers software architectural enforcements needs (Section 5). The code in Figure 1 demonstrates how implicit boxing can be made explicit, which could be used as the first step to replacing uses of the java.lang.Integer class with an alternative class. 2. CLASS LIBRARY MIGRATION 2.1 Canonicalization Class library migration is a general software evolution need: Of- One use we found for class library migration was when we started ten it is desirable to remove the use of a legacy library and directly to employ the Google Collections library [8]. The library includes use its replacement instead [1]. The solution for this problem de- extra support for programming with generics in Java, including in- vised by Balaban et al. includes a type constraint solver that finds terfaces and operations to support functional programming styles. the largest set of code locations that can be safely changed, even in For example, we had a need in Arcum to support operations that the presence of synchronized methods. For example, uses of the al- are lazily executed. This division of definition and execution al- ways synchronized Vector class can be changed to uses of the more lowed us to separate the knowledge of how to initialize an object efficient ArrayList class, where the ArrayList instances are synchro- from the knowledge of when to initialize it. We initially defined a nized only when necessary. parameterized Thunk<T> interface to achieve this, which declared Arcum supports a complementary variation of class library mi- a single, no-argument method with a return type of T. Looking into gration. Instead of determining the largest set of code locations the Collections library we found that the Supplier interface fit our that can be safely migrated, Arcum’s approach is to have the loca- needs exactly. By using an interface defined in another library, we tion set explicitly described; for example, one description might be were able to make our own use of the interface less mysterious “all uses of Vector in package p or by class C.” When the set can- compared to the original solution. By writing code that conforms not be transformed safely, the starting option presents the user with to a more standardized interface there is a better chance to integrate static error messages. All errors have to be resolved before trans- independently developed code that followed the same standards. formation is allowed. In some instances, the location set specified might match more code than expected, requiring the user to narrow 2.2 Removing Puns: De-Canonicalization the set’s definitions; in other instances, the set definition is correct Of course, there are always trade offs with using standard libraries. but modifications need to be made to the code itself first, to bring One risk of transforming all similar-looking uses to use the same it into conformance; in yet other cases, the user might realize, by canonical form is that two uses that only accidentally look simi- the nature of the errors, that he or she needs to take a completely lar could be mistaken to belong to the same concern. Such similar different approach. In this way, Arcum gives the programmer an uses could be called “puns.” For example, if there are two meth- opportunity to interact with the tool, helping to ensure that his or ods that accept an instance of Supplier<String>, are they related, her conception of the system matches the actual implementation. or would one be better typed as DelayedObject<String> while the The key to Arcum’s support for matching uses of class libraries other is typed as DefaultValue<String>? The answer depends on is the DeclarationElement type, derived from the same term used by your circumstances. Tip et al. to describe all local variables, fields, return types, and cast Providing different class definitions to prevent puns can assist expressions [24].