
A Dissertation Submitted to Department of Creative Informatics, Graduate School of Information Science and Technology, The University of Tokyo A Study on a Single Construct for Events, Aspects, and Behaviors (イベント、アスペクト、ビヘイビアのための 単一言語機構に関する研究) By 莊 永裕 YungYu ZHUANG Supervisor: 千葉 滋 Shigeru CHIBA December 2013, Copyright ⃝c 2013 YungYu ZHUANG. All Rights Reserved. Abstract Programming paradigms are so important that a lot of research activities are devoted to the support for them. How to support the implementation of paradigms can be classified into three types of approaches: by design pat- terns, by dedicated constructs, and by generic constructs. However, none of them are sufficient. Design patterns can be used to implement most paradigms but not all. Furthermore, without language support the code tends to scatter and tangle. Dedicated constructs greatly improve the mod- ularity of code, but also increase the number of constructs in a language supporting multiple paradigms; a large number of constructs complicates the language design. Generic constructs can be considered as a potentially good approach, but the number of supported paradigms in current research is quite limited; existing generic constructs are not flexible enough to support more paradigms. To overcome the problem that existing generic constructs are not flexible enough, this thesis proposes a new generic construct, method slots, based on our observation of the common ground among the implementations of three important paradigms in the real world: OOP, the event-handler paradigm (event-driven programming), the aspect paradigm (aspect-oriented program- ming). The common ground has never been noticed before this thesis since the dedicated constructs for these paradigms were individually developed from the beginning. The observation on the similarities motivates us to extend the methods in JavaScript to method slots, which can be used as methods, events, and advices. To demonstrate how method slots can be used in practice, a Java-based language named DominoJ is proposed with a compiler implementation. We then evaluate DominoJ by comparing with existing languages, running benchmarks for it, and rewriting programs as case studies. The concept of method slots is very simple and easy to extend. To support iii this argument, we demonstrate how to extend method slots by taking the ex- ample of the reactive paradigm (functional-reactive programming). We first compare the reactive paradigm with the most similar one in the paradigms supported by method slots: the event-handler paradigm. We find that the major difference between them is whether the event composition is automatic or not. Then we discuss the definitions for event composition in existing event mechanisms, and get the conclusion that existing event mechanisms lack an inference-based definition to automatically select events for a higher-level event. This thesis proposes such an inference-based definition by adding only one more operator for method slots. How the operator can be used for the reactive paradigm is presented with a feasible implementation and discussed in detail to clarify the limitations. iv Acknowledgments First of all, I would like to express my deep gratitude to my supervisor, Prof. Shigeru Chiba. He always gives me great advice on doing research and guided me through the process of this thesis. I learned a lot from him, especially how to study and present. He is also the person who kindly gave my the chance to start my research again in Japan. I also would like to thank the thesis committees: Prof. Hiroshi Esaki, Prof. Kei Hiraki, Prof. Mary Inaba, Prof. Hideki Nakayama, Prof. Hidehiko Masuhara, and Prof. Shigeru Chiba. They gave me valuable comments on not only the contents of this research but also the arguments of this thesis. My grateful thanks go to all my colleagues in Chiba's group. In particular, I would like to thank Prof. Yoshiki Sato, Michihiro Horie, Masayuki Ioki, Shumpei Akai, Fuminobu Takeyama, Maximilian Pascal Scherr, Kazuhiro Ichikawa, and Hiroshi Yamaguchi. They gave me many help in both life and research. I would like to thank all my family. I always get encouragement from my parents, my elder brother, and my wife's parents. I am very grateful to my wife; it is she who encouraged me to come to Japan. She takes care of our daughter alone to let me concentrate on my research. I was even unable to accompany her when our son was born. Without her support it is impossible to finish this thesis. Finally I appreciate the Development of System Software Technologies for post-Peta Scale High Performance Computing project from JST CREST and the CompView Global COE program from JSPS for the financial support (as a research assistant), and the scholarship from Interchange Association (Japan). They supported me to complete my doctoral program. v Contents 1 Introduction 1 1.1 Motivating problems ........................ 2 1.2 Solution by this thesis ....................... 4 1.3 Position of this thesis ....................... 6 1.4 Structure of this thesis ....................... 7 2 Backgrounds 9 2.1 Programming paradigms ...................... 9 2.1.1 Object-oriented programming ............... 10 2.1.2 The event-handler paradigm ................ 17 2.1.3 The aspect paradigm ................... 19 2.1.4 The reactive paradigm ................... 25 2.2 Supporting the implementation of paradigms ........... 26 2.2.1 Design patterns ...................... 26 2.2.2 Dedicated constructs and the unification ......... 30 2.2.3 Generic constructs and the integration .......... 31 2.3 Comparing the three approaches .................. 32 3 Method Slots 37 3.1 Introduction ............................ 37 3.2 Motivation ............................. 38 3.3 DominoJ .............................. 42 3.3.1 Method slots ........................ 42 3.3.2 Assignment operators for method slots .......... 45 3.4 Evaluation ............................. 51 3.4.1 The implementation .................... 51 3.4.2 Microbenchmarks ..................... 56 CONTENTS vii 3.4.3 Compiling and running the DaCapo benchmark suite ... 59 3.4.4 Method slots and design patterns ............. 64 3.4.5 The event-handler paradigm ................ 73 3.4.6 The aspect paradigm ................... 79 3.4.7 Summary of the coverage ................. 84 3.4.8 Event-handler vs. Aspect ................. 85 3.5 Case study ............................. 86 3.5.1 The events and delegates examples in C# tutorials .... 86 3.5.2 The Observer pattern in JHotDraw ............ 94 3.5.3 The aspects in AspectTetris ................ 102 3.6 Related work ............................ 108 3.7 Summary .............................. 111 4 An Extension for Supporting the Reactive Paradigm 113 4.1 Introduction ............................ 113 4.2 Emulating the reactive paradigm by the event-handler paradigm . 114 4.2.1 An example of the reactive paradigm ........... 115 4.2.2 The event-handler paradigm can do the same thing .... 116 4.2.3 The major difference between the two paradigms ..... 118 4.2.4 The definitions of higher-level events in existing event mechanisms ........................ 118 4.2.5 The lack of inference rules ................. 123 4.3 ReactiveDominoJ .......................... 123 4.3.1 Using DominoJ for the event-handler paradigm ...... 123 4.3.2 The braces operator for the inference-based definition .. 124 4.3.3 The implementation of the reactive extension ....... 130 4.4 Discussion ............................. 139 4.4.1 Preliminary microbenchmarks ............... 139 4.4.2 Comparing with DominoJ ................. 141 4.4.3 Comparing with AspectJ .................. 142 4.4.4 For the reactive paradigm ................. 143 4.5 Related work ............................ 149 4.6 Summary .............................. 151 5 Conclusions 153 Bibliography 159 viii CONTENTS List of Figures 2.1 The objects in the music player example ............. 11 2.2 The model of the music player example .............. 11 2.3 The musicPlayer object can be replaced with the musicPlayerH object ............................... 12 2.4 The model of the media player modified from the music player example .............................. 13 2.5 The class hierarchy for mediaEngine of the media player example 14 3.1 In JavaScript, both an integer and a function are fields on an object 42 3.2 A method slot is an extended field that can keep more than one function closure .......................... 43 3.3 The keywords $caller and $predecessor .............. 51 3.4 The average time of continuously calling a method in Java and DominoJ, including the reflection version ............. 58 3.5 The average time of using the operators for method slots .... 59 3.6 The average execution time of the 12 DaCapo benchmarks com- piled by the three compilers .................... 62 3.7 The box plot of the execution time for the DaCapo benchmarks . 63 3.8 The execution order of the shape example in EScala and DominoJ 78 3.9 Adding another advice to the shape example in AspectJ and DominoJ .............................. 83 3.10 Calling proceed in AspectJ and DominoJ ............. 83 3.11 The design decision of EScala, AspectJ, and DominoJ ...... 85 4.1 An example of spreadsheet ..................... 116 4.2 The DominoJ version needs the explicit bindings for the event composition of this.changed .................... 128 LIST OF FIGURES ix 4.3 According to the default closure of update, this.update depends on b1.getValue and c1.getValue .................. 128 4.4 According to Listing 4.3, getValue
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages182 Page
-
File Size-