Example-Based Live Programming for Everyone Building Language-Agnostic Tools for Live Programming with LSP and Graalvm
Total Page:16
File Type:pdf, Size:1020Kb
Example-Based Live Programming for Everyone Building Language-Agnostic Tools for Live Programming with LSP and GraalVM Fabio Niephaus Patrick Rein Jakob Edding Hasso Plattner Institute Hasso Plattner Institute Hasso Plattner Institute University of Potsdam University of Potsdam University of Potsdam Potsdam, Germany Potsdam, Germany Potsdam, Germany [email protected] [email protected] [email protected] Jonas Hering Bastian König Kolya Opahle Hasso Plattner Institute Hasso Plattner Institute Hasso Plattner Institute University of Potsdam University of Potsdam University of Potsdam Potsdam, Germany Potsdam, Germany Potsdam, Germany [email protected] [email protected] [email protected] Nico Scordialo Robert Hirschfeld Hasso Plattner Institute Hasso Plattner Institute University of Potsdam University of Potsdam Potsdam, Germany Potsdam, Germany [email protected] [email protected] Abstract from programming environments. Further, we demonstrate Our community has explored various approaches to improve how our approach enables the use of elp in the context of the programming experience. Although many of them, such polyglot programming. We illustrate the consequences of as Example-Based Live Programming (elp), have shown to our approach by discussing its advantages and limitations be effective, they are still not widespread in conventional and by comparing the features of our system to other elp programming environments. A reason for that is the effort systems. Moreover, we give an outlook of how tools that rely required to provide sophisticated tools that rely on run-time on run-time information could be built in the future. This information. To target multiple language ecosystems, it is in turn might motivate future tool builders and researchers often necessary to implement the same concepts, but for dif- to consider implementing more tools in a language-agnostic ferent languages and runtimes. Two emerging technologies way from the start to make them available to a broader audi- present an opportunity to reduce this effort significantly: the ence. Language Server Protocol (lsp) and language implementa- tion frameworks such as GraalVM’s Truffle. In this paper, we CCS Concepts: • Software and its engineering ! Inte- show how an elp system can be built in a language-agnostic grated and visual development environments; Software way by leveraging these two technologies. Based on our maintenance tools; Runtime environments. approach, we implemented the Babylonian Programming system, an elp system that has previously only been imple- mented for exploratory ecosystems. Our system, on the other Keywords: Live Programming, Exploratory Programming, hand, brings elp for all languages supported by the GraalVM Language Server Protocol, GraalVM, Truffle, Visual Studio to Visual Studio Code (VS Code). Moreover, we outline what Code a language-agnostic infrastructure needs to provide and how the lsp could be extended to support elp also independently ACM Reference Format: Permission to make digital or hard copies of part or all of this work for Fabio Niephaus, Patrick Rein, Jakob Edding, Jonas Hering, Bas- personal or classroom use is granted without fee provided that copies are tian König, Kolya Opahle, Nico Scordialo, and Robert Hirschfeld. not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for third- 2020. Example-Based Live Programming for Everyone: Building party components of this work must be honored. For all other uses, contact Language-Agnostic Tools for Live Programming with LSP and the owner/author(s). GraalVM. In Proceedings of the 2020 ACM SIGPLAN International Onward! ’20, November 18–20, 2020, Virtual, USA Symposium on New Ideas, New Paradigms, and Reflections on Pro- © 2020 Copyright held by the owner/author(s). gramming and Software (Onward! ’20), November 18–20, 2020, Virtual, ACM ISBN 978-1-4503-8178-9/20/11. USA. ACM, New York, NY, USA, 17 pages. https://doi.org/10.1145/ https://doi.org/10.1145/3426428.3426919 3426428.3426919 1 Onward! ’20, November 18–20, 2020, Virtual, USA F. Niephaus, P. Rein, J. Edding, J. Hering, B. König, K. Opahle, N. Scordialo, and R. Hirschfeld 1 Introduction is to allow programmers to use the best language, library, Our community has created various approaches to improve framework, or tool for the job and thus fosters software reuse. the programming experience through Exploratory and Live On the other hand, this also means that they have to deal Programming [26], in particular through tools making use with additional cognitive overhead, for example distinguish- of run-time information such as Whyline or Example-Based ing between different language semantics. An elp system Live Programming (elp)[1, 13]. Nevertheless, many of these can help programmers to better understand such differences tools are not widespread, in particular not in conventional when building polyglot applications. programming environments. This is often not the result of a In this paper, we show how a new infrastructure can pro- conceptual limitation, as many of these tools do not depend vide a complex programming tool with a live feedback loop on specific programming languages, programming environ- for multiple languages. In particular, we describe and evalu- ments, or execution environments. We argue that part of ate how an elp system can be built in a language-agnostic the problem is the effort required to provide a tool for dif- way on top of the lsp and the Truffle instrumentation frame- ferent ecosystems, as this means re-implementing the user work. On the one hand, our approach makes elp usable uni- interface (ui) of the tool in the corresponding programming formly across languages and development environments. On environments and the necessary instrumentation in the cor- the other hand, it also enables elp for polyglot programming, responding execution environments. While some adapta- where programmers not only have to deal with cognitive tions for specific environments will always be required, the challenges of one, but many languages at the same time. To core mechanisms of a tool may not differ much between demonstrate our approach, we implement the Babylonian implementations and could be reused. Programming system [23, 25], an elp system that has previ- Two recent trends provide an opportunity that may enable ously only been implemented for exploratory ecosystems, tool builders to support various environments and languages, on top of Truffle’s lsp implementation and the its extension while only implementing the core mechanisms of their tools for Visual Studio Code (VS Code). once: the Language Server Protocol (lsp) and the Truffle instrumentation framework. The lsp decouples Integrated Contributions: Development Environments (ides) from concrete program- ming languages, so that programmers are free to choose • An approach for extending the Language Server Pro- what kind of ide they use for writing code in a specific lan- tocol with a live feedback loop to support elp systems, guage [18]. The Truffle instrumentation framework [30], on • A language-agnostic implementation strategy for a the other hand, enables language-agnostic implementations Babylonian Programming system, and of program instrumentation infrastructures. This framework • A discussion of to what extent elp can be provided in is part of the Truffle language implementation framework a language-agnostic and environment-agnostic way, used to implement all languages for the GraalVM [33]. More based on a prototypical implementation of said ap- importantly, Truffle already provides an lsp server based on proach and strategy. its instrumentation framework [28]. An example for sophisticated tool support that may be In the remainder of this paper, we give a short introduction implemented based on these technologies is elp. elp nar- to elp and provide an overview of current implementation rows the gap between static source code and the dynamic strategies to illustrate how these result in specialized imple- behavior of a program. While programmers write code, an mentations in Section 2. In Section 3, we introduce lsp and elp system uses user-provided examples to invoke annotated the Truffle instrumentation framework. Based on this, we functions, and to provide fine-grained, live feedback on the present our general approach for a language-agnostic elp im- resulting program behavior. Currently, most existing imple- plementation in Section 4. In Section 5, we describe technical mentations of elp systems are based on highly specialized details of the implementation. To illustrate the consequences programming systems and adapted execution environments. of our approach, we demonstrate the achieved programming For widespread adoption, however, elp needs to be available experience with two walkthroughs in Section 6 and provide in conventional, general-purpose ides and should work with a discussion of the feasibility of providing elp in a language- unmodified execution environments. agnostic and environment-agnostic way in Section 7. Finally, As a result of implementing tools in a language-agnostic we discuss related work in Section 8 and state our conclu- way, programmers can always use their preferred set of tools sions in Section 9. to develop in different languages. This makes the program- ming experience more consistent [20]. Moreover, such tools 2 Example-Based Live Programming: can