Live Programming with Code Portals
Total Page:16
File Type:pdf, Size:1020Kb
Live Programming with Code Portals Alexander Breckel and Matthias Tichy Institute of Software Engineering and Compiler Construction Ulm University, Germany {alexander.breckel,matthias.tichy}@uni-ulm.de Abstract a time. If developers identify a mistake when using such a Programming is often a cycle between programming activi- wizard, they typically need to start from scratch or go back ties and understanding the results of those activities. Hence, several steps, which makes performing refactorings a rather modern development environments support many different heavy-weight process. tools to increase the speed of development, e.g., for refac- Different approaches already exist which support live pre- toring or to visualize variable values or type information view of various development activities. For live-evaluation in a running program. However, current development en- of expressions, some approaches use a separate view [6], vironments provide these different tools in various ways, whereas others embed results directly under [10], beside [7], from wizards for refactorings with special preview pages, to or near the [1] respective expression in the source code view. tooltips and watch views for showing specific information. In previous work [3], we introduced code portals, a mech- In this paper, we present code portals as a generic technical anism to integrate arbitrary textual information into source concept to enable showing live and continuously updated in- code documents. Code portals provide a generic and ver- formation about the program and its state. We illustrate code satile way to provide both, live-evaluation for expressions, portals on three different types of programming languages, and live-previews for editor features, from right within the procedural, functional and homoiconic. A qualitative user main source code view. In contrast to other techniques of em- study shows that code portals and their applications are seen bedding additional information inside the source code view, helpful by users. A video demonstration can be found at: however, code portals maintain complete editability of em- https://goo.gl/PumhQR bedded content, while providing a low visual overhead and a handling already familiar to programmers. Integrated con- Keywords live evaluation, refactoring, function inlining, tent therefore can be selected, copied, and modified using code portals, source code editor existing text editing operations. This paper builds upon this previous work [3], where we 1. Introduction present how code portals can be utilized to present program- ming context and improve code comprehension. In this pa- Contemporary integrated development environments (IDEs) per, we extend our previous work on live-evaluation to three often provide, unlike the name suggests, only little integra- different types of programming languages (functional, im- tion between different editor features. Information like, for perative, homoiconic) to show the genericity of the code por- example, debugging state or code structure, is often accessed tal concept. Further, we show how code portals can be used through a multitude of visually and conceptually separate for live-previews of program refactorings, including meta- views, instead of being displayed within the main source programming in homoiconic languages. Finally, we present code view. Furthermore, in many cases this information a generic mechanism to enable live-previews using code por- needs to be requested and updated explicitly. tals for various typical editor features. Source code changes, like various types of refactorings, We have implemented all features presented in this paper are often implemented in wizards, which only provide spe- in a prototypical source code editor. Based on this imple- cific preview capabilities and only support one refactoring at mentation, we have furthermore performed an initial quali- tative usability study, which suggests that the presented tech- niques can be quickly grasped by programmers and help in Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and understanding and writing source code. the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, to republish, to post on servers, or to redistribute to lists, contact After an introduction to code portals in the next section, the Owner/Author(s). Request permissions from [email protected] or Publications Dept., ACM, Inc., fax +1 (212) 869-0481. we describe different types of live-information which can be CONF ’yy Month d–d, 20yy, City, ST, Country embedded into source code in Sections 3 and 4, and illustrate Copyright © 20yy held by owner/author(s). Publication rights licensed to ACM. ACM 978-1-nnnn-nnnn-n/yy/mm. $15.00 them with concrete examples. Section 5 provides a general- DOI: http://dx.doi.org/10.1145/nnnnnnn.nnnnnnn ization of these use-cases that facilitates live-previews for a instead open a code portal showing the definition of DB right wide set of editor features. In Sections 6 and 7, we present within the code of PersistentDB: our prototypical implementation of a standalone text editor, and initial results of a qualitative study. After a discussion of 1 class PersistentDB implementsDB{ related work in Section 8, we conclude and give an outlook 2 ···· on future work. 76 interfaceDB extends Serializable { 77 ····void store(String k, String v); 78 ····String retrieve(String k); 2. Code Portals 79} Existing programming editors support a wide variety of 3} ways to display additional information inside the main ... source code view. For example, many IDEs display API doc- 76 interfaceDB extends Serializable { umentation or compilation errors with tool-tips or overlays. 77 ····void store(String k, String v); While this in principle represents a non-intrusive way to dis- 78 ····String retrieve(String k); play optional information, the fact that tool-tips and similar 79} concepts obstruct the view on underlying code makes them unsuitable for a permanent display of live-evaluation results. Therefore, some tools [7, 10] with live-evaluation capabil- The code portal, visible at the top, is highlighted with a blue ities choose to embed live-information in between existing border and background, but otherwise uses the same font and source code locations. This minimizes the visual distance mono-space grid as the surrounding code. Line numbers are between evaluation results and respective code locations and adjusted to indicate where the content originates from. The clarifies the pairing of code and results in the case of mul- dotted area at the bottom represents the source region of the tiple simultaneous embeddings. However, these additional code portal further down in the file and is displayed using a embeddings are not part of the surrounding code document matching blue color. and cannot be selected and manipulated directly with exist- The Link between the source and destination area of ing editor operations. the portal is maintained, and modifications within a code Code portals follow a different approach. Similar to non- portal also affect the original code location, which inspired obstructive embeddings known from other tools, code por- the name portal. Conversely, changes to the original code tals provide a way to embed textual content into the source locations, e.g., when performing refactoring operations, are code document. However, the content is – character by char- also immediately visible within the code portal. This allows acter – integrated into the surrounding source code. This the programmer to extend the interface definition, or work makes it possible to select, copy, and in some cases even ma- on both locations in parallel without having to navigate back nipulate embedded content, just as if its characters were part and forth. of the original code document. Analysis tools, and the com- Unlike similar visualization mechanisms, code portals piler itself, though, can safely ignore all embedded content represent first-class citizens within a document and can to avoid syntactic or semantic errors. therefore be nested, which allows a composition of differ- To illustrate this, the following example, taken from [3], ent editor features. After creation, code portals can subse- shows a definition of an empty Java class PersistentDB, quently be moved, resized, closed, and have their contents which derives from an interface DB further down in the file: merged into the underlying code location. Merging works by replacing the code underneath a portal, which is empty in 1 class PersistentDB implementsDB{ the aforementioned example, with the code inside the portal. 2 ···· This has the effect that all visible characters stay in place 3} while the portal borders disappear: ... merge 76 interfaceDB extends Serializable { create 77 ····void store(String k, String v); abcdefghij abghefghij abghefghij 78 ····String retrieve(String k); 79} Here, a portal is created hiding the characters cd and show- ing the characters gh from further right in the string instead. Merging the portal replaces cd with gh. In order to implement the class PersistentDB, a pro- Portals are displayed by a combination of borders and grammer likely needs access to the interface definition of DB. colors. Rounded corners allow the user to distinguish be- This is normally achieved by opening a second editor view, tween different nesting levels and overlappings: or navigating back and forth between the corresponding code locations. With our approach, however, the programmer can abcdefghij abcdefghij abcdefghij In the left example, the green portal is nested within the blue Here, code portals were used to inline a function definition, portal. In the middle example, both portals are side-by-side, as will be further explained in Section 4. Note the consistent whereas the right example shows an inverted nesting. alignment of if, then and else, which would not have been Colors indicate linked code fragments of the same origin.