Information
Meeting: Monday & Wednesday, 2:00PM-3:15PM in WWH 312
Instructor: Randy Shepherd
Email: rjs471 [at] nyu.edu
Skype: randy.j.shepherd
Office hours: Tuesday & Thursday, 4:45PM-6:15PM in WWH 425
Graders: Chen Chen - cc4772 [at] nyu.edu & Omer Solmazer os788 [at] nyu.edu
Description
Object-oriented (OO) programming has emerged as a significant software development methodology. The goal of this course is to learn how to build and evolve large-scale programs using object-oriented programming. To this end, the course introduces the important concepts of object-oriented languages and design and explores how these concepts are implemented.
Prerequisites: Computer Systems Organization (CSCI-UA 201).
Acknowledgments: This course is based on the Object-Oriented Programming course designed by Robert Grimm.
Objectives
In exploring object-oriented programming, we investigate three questions:
- Design: How do we think about a program in terms of objects? To answer this question, we explore the Pillars of OOP, S.O.L.I.D. and Design Patterns.
- Language Primitives: How do we express object orientation? To answer this question, we explore subjects including classes, polymorphism, inheritance, method dispatch and generics.
- Language Implementation: How do we realize object-oriented primitives? To answer this question, we explore subjects including virtual method dispatch and method overloading.
Textbooks
Required:
- Object-Oriented Design and Patterns, 2nd ed. by Cay Horstmann, Wiley, 2005
- C++ for Java Programmers by Mark Weiss, Prentice Hall, 2003
Suggested:
- The C++ Programming Language, 4th ed. by Bjarne Stroustrup, Addison-Wesley, 2015.
Project
The focus of our exploration of object-oriented programming is a translator from Java to C++. You design, implement, and evaluate your own translator as a term-long project, working in teams of four to five students. In fact, you build two versions of your translator, taking half a term for each version and presenting your work in class on completion of each version. To make the project manageable, your translator only translates a restricted subset of Java into an even more restricted subset of C++; though the second version covers more functionality than the first version. I also provide you with “helper” code, notably for parsing and formatting source files.
Each group selects a speaker, who coordinates with the members of the group and with me. A new speaker is elected at the middle of the term.
Your group’s midterm and final project presentations address three main issues:
- What are the design and implementation of your translator?
- How do you ensure that the translator meets the project requirements? Notably, how do you convince yourself and others that the translator actually works?
- What was easy, hard, and/or surprising and how did that impact your translator?
You have a 12 minute slot for your presentation, which includes a demo of your translator and time to set up your laptop.
Languages
This course relies on three different programming languages:
- The source language is the language of programs serving as inputs to the translator; it is a restricted version of Java.
- The target language is the language of outputs of the translator; it is a restricted version of C++.
- The translator language (for lack of a better term) is the language of the translator itself; it is the full Java 7.0 née JDK 1.7 language.
In more detail, the source language is Java without nested classes, anonymous classes, interfaces, enums, annotations, generics, the enhanced forloop, varargs, and automatic boxing andunboxing. Furthermore, the source language omits support for synchronization, i.e., synchronized methods andstatements, and strict arithmetic operations, i.e. thestrictfp modifier. It also omits support for transient and volatile fields as well as native methods. Finally, you may omit method overloading but not method overriding forthe first version of the translator. It also omits features new to Java 8, notably lambdas and functional interfaces.
The target language is C++ without virtual methods, inheritance, and, ingeneral, templates. It also omits features new to C++11, notably lambda abstractions and type inference, e.g., auto and decltype. It does, however, include gcc's statement expressions, i.e., ({ … }). When compared to C, the target language does include support for basic classes, exceptions, and name spaces. For the first version of the translator, you can ignore memory management and assume an infinite main memory. For the second version of the translator, you need to automatically reclaim unused memory through a so-called smart pointer. The smart pointer library, as well as any library support for implementing Java arrays, may use templates.
Most Java statements and expressions translate directly into the corresponding C++ statements and expressions (modulo minor language differences). As a result, the main challenges for the course project are figuring out (1) how to translate Java class hierarchies into C++ without inheritance and (2) how to implement Java’s virtual method dispatch in C++ without virtual method dispatch, (3) how to select the right overloaded method, and (4) how to automatically manage memory without an existing garbage collector. Note that we will explore how to approach each challenge in class; we will also leave the latter two challenges for the second version of the translator.
Besides the programming language itself, any version of Java includes a rather extensive set of platform libraries, with the facilities in the java.lang package being tightly integrated with Java’s execution model. For our translator, we only support the hashCode(), equals(), and toString() methods in java.lang.Object and the printing of numbers and strings through out.print() and out.println() in java.lang.System. Also, some of the Class class. Furthermore, we do not support the dynamic loading of Java classes, but rather translate all Java classes of the source program into one C++ program.
Please note that the translator need not perform any correctness checks on source programs; in other words, you can assume that source programs are free of compile-time errors. At the same time, when writing your own Java test programs, it seems prudent to test them with a regular Java compiler.
Tools and Resources
An important dimension to this course is to demonstrate how OOP is weilded in large scale software development projects. Towards that end we are using a very modern and sophisticated toolchain that would be similar to that used in a professional context.
Note that homework 1 provides a detailed guide on our toolchain and the installation thereof.
For Java, we use the Java 2 Platform Standard Edition 7.0, née JDK 1.7, or later.
For C++, we use gcc, the GNU Compiler Collection, as our compiler. It is the default compiler for Linux and included with Apple’s Xcode for Mac OS X.
If you are running Windows, you will need to run a virtual machine. Again detailed instructions are in the homework 1.
Like any large-scale software projects, we rely on a build toolchain to compile, assemble, test and execute our project. In this course, we will use SBT. SBT is most well known for Scala projects, but it works equally well for Java projects. Between the built-in capabilities of SBT and the extensions I have created for it, many headaches you might typically be associated with working on large software projects should be ameliorated.
To simplify the task of reading source files in one language, translating them into another language, and then printing source files for that language, we use the xtc toolkit for source-to-source translators. xtc includes a parser for Java source files, which converts the external, textual representation into an internal tree representation. It also includes support for traversing, modifying, and pretty-printing such trees.