Towards Customizable Pedagogic Programming Languages
Total Page:16
File Type:pdf, Size:1020Kb
TOWARDS CUSTOMIZABLE PEDAGOGIC PROGRAMMING LANGUAGES by Kathryn E. Gray A dissertation submitted to the faculty of The University of Utah in partial fulfillment of the requirements for the degree of Doctor of Philosophy in Computer Science School of Computing The University of Utah August 2006 Copyright c Kathryn E. Gray 2006 All Rights Reserved THE UNIVERSITY OF UTAH GRADUATE SCHOOL SUPERVISORY COMMITTEE APPROVAL of a dissertation submitted by Kathryn E. Gray This dissertation has been read by each member of the following supervisory committee and by majority vote has been found to be satisfactory. Chair: Matthew Flatt Wilson Hsieh Gary Lindstrom Joe Zachary Gilad Bracha THE UNIVERSITY OF UTAH GRADUATE SCHOOL FINAL READING APPROVAL To the Graduate Council of the University of Utah: I have read the dissertation of Kathryn E. Gray in its final form and have found that (1) its format, citations, and bibliographic style are consistent and acceptable; (2) its illustrative materials including figures, tables, and charts are in place; and (3) the final manuscript is satisfactory to the Supervisory Committee and is ready for submission to The Graduate School. Date Matthew Flatt Chair, Supervisory Committee Approved for the Major Department Martin Berzins Chair/Dean Approved for the Graduate Council David S. Chapman Dean of The Graduate School ABSTRACT In introductory education, pedagogic tools and languages can help focus students on the fundamental programming concepts. Subsets of a professional language support the presentation of the language’s syntax in step with the presentation of the underlying concepts, relieving students and instructors from superfluous details. This dissertation presents the design and implementation of pedagogic tools integrated with an introduc- tory computer science course. The tools described in this dissertation include languages, compilers, and libraries tailored to improve introductory education for students and instructors. Specifically, • three pedagogic subsets of the Java programming language. My method of designing these subsets, through a combination of assessing the supported curriculum and observation, may serve as a guide for creating other subsets. Discussion includes experiences using these subsets in classrooms, and how observations guided the design and modifications of the subsets. • an extension to Java supporting fine-grained interoperability between languages, which facilitates the reuse of existing libraries accessible within pedagogically appro- priate subsets of a language. More generally, I demonstrate how to support general interoperability between two languages. Discussion includes the interoperability mechanism and a library implementation using the language extension. • an examination of the compiler implementation supporting the subsets and in- teroperability extension. The compiler maps Java constructs into similar Scheme constructs for ease of use of Java programs within Scheme and vice versa. Discussion includes parsing multiple languages with coherent error messages, representing Java compilation units, and supporting dynamic checking of Scheme values in Java. To my parents CONTENTS ABSTRACT ...................................................... iv LIST OF FIGURES ............................................... ix LIST OF TABLES ................................................. x ACKNOWLEDGEMENTS ......................................... xi CHAPTERS 1. LANGUAGE SUPPORT FOR PEDAGOGY ..................... 1 1.1 Support from Language and Environment . 2 1.1.1 Language Support . 2 1.1.2 Environment Support . 4 1.2 Pedagogic Libraries . 4 1.3 Customizing Languages . 5 1.4 Towards Customization . 5 1.4.1 Pedagogic Subsets . 6 1.4.2 Programming in Multiple Languages . 7 2. CREATING PEDAGOGIC LANGUAGES ....................... 9 2.1 A Curriculum and Its Requirements . 9 2.2 Observations . 11 2.2.1 Observations Using Non-ProfessorJ Compilers . 11 2.2.2 Observations Using ProfessorJ Compiler . 16 2.3 General Lessons . 18 2.4 ProfessorJ Languages . 20 2.4.1 Beginner . 20 2.4.1.1 Ongoing observation. 23 2.4.2 Intermediate . 24 2.4.2.1 Ongoing observation. 25 2.4.3 Advanced . 26 2.5 Connecting to the Environment . 29 2.6 Supporting Error Messages . 31 2.7 Related Work . 33 2.7.1 Language Levels . 33 2.7.2 Pedagogic Languages . 35 2.7.3 Pedagogic Tools Without Language Levels . 35 3. ADDING LIBRARY SUPPORT ................................ 37 3.1 Language Mixings . 38 3.1.1 A Dynamically-Checked Pedagogic Language . 38 3.1.2 Parametrically Polymorphic Library . 39 3.1.3 A Dynamically-Typed Library . 41 3.2 Extending the Language with dynamic ........................... 41 3.2.1 Syntax and Extensions . 41 3.3 Writing Libraries with dynamic ................................. 43 3.3.1 Dynamically-Checked Student Language . 43 3.3.2 Polymorphic Library . 44 3.4 A Teaching Library . 44 3.4.1 The Library . 45 3.4.2 Implementation Options . 45 3.5 The Implementations . 47 3.5.1 Image . 47 3.5.1.1 Native Method Implementation. 47 3.5.1.2 Java + dynamic Implementation. 49 3.5.1.3 Discussion. 49 3.5.2 View . 50 3.5.2.1 Native Method Implementation. 50 3.5.2.2 Java + dynamic Implementation. 50 3.5.2.3 Discussion. 53 3.5.3 GameWorld . 53 3.5.3.1 Native Method Implementation. 53 3.5.3.2 Java + dynamic Implementation. 55 3.5.3.3 Discussion. 55 4. EXPLORING DYNAMIC ...................................... 57 4.1 Type Checking dynamic ....................................... 57 4.2 Protecting Type-Safety . 60 4.2.1 Contracts . 60 4.2.2 Contracts and Java + dynamic ............................. 61 4.2.3 Checking Contracts . 63 4.3 Adding Support for dynamic ................................... 67 4.3.1 Mirrors and Reflection . 67 4.3.2 Implementing dynamic with Mirrors . 68 4.3.3 Static Types from Dynamic Values . 70 4.4 Related Work . 71 4.4.1 Mixing Dynamic and Static Types . 71 4.4.2 Language Interoperability . 72 5. BUILDING THE SYSTEM ..................................... 74 5.1 Compiling for Multiple Languages . 75 5.1.1 Parsing . 75 5.1.2 Type Checking Multiple Languages . 76 5.1.3 Error Messages . 76 5.2 Type Checking dynamic ....................................... 77 5.3 Compiling to Scheme . 78 vii 5.3.1 Compilation Units . 78 5.3.2 Classes . 81 5.3.3 Fields and Methods . 82 5.3.4 Nested Classes . 84 5.3.5 Statements and Expressions . 85 5.3.6 Native Methods . 88 5.4 Compiling for Interoperability . 88 5.4.1 Objects and Methods . 88 5.4.2 Fields . 89 5.4.3 Inserting Dynamic Checks . 89 5.4.4 Supporting Equality and Casting . 92 5.4.5 Inheritance . 92 5.4.6 Naming Conventions . ..