Unformatted text preview:

Designing Programs with ClassSam Tobin-Hochstadt and David Van HornJanuary 7, 20142This book introduces the fundamental elements of class-based program design.The book is also available in PDF form here.Contents34CONTENTSPreface5CONTENTS7This book is adrafttextbook to accompany Fundamentals of Computer ScienceII (Honors): Introduction to Class-Based Program Design at Northeastern University.1It began its life as a series of course notes from the Spring 2011 incarnation of theclass, evolved during Spring 2012, and is now being revised throughout the Spring2013 semester.The book is very much a work in progress, which means there are large omis-sions and numerous errors. Moreover, it's certain to change as the course progresses.Your patience, feedback, and bug reports are greatly appreciated. The book and itsaccompanying software are maintained on Github at the following URL:https://github.com/dvanhorn/dpc1http://www.ccs.neu.edu/course/cs2510h/8CONTENTSDesign RecipesIt puts a lot of emphasis on something called The Design Recipe, whichsounded hokey to me at rst, but when I was shown what The DesignRecipe was, I realized, even as someone who's been programming for 35years, that rather than code a solution to something complex in say, anhour, after 15-20 minutes, when I thought I was a third done, I was actu-ally and suddenly completely done, sometimes almost feeling like magic.It basically puts a high emphasis on thinking and designing rst, writingtest cases very early, picking the right program structure, and then llingin the blanks and expanding them in a few places. Following the DesignRecipe, not only was I often suddenly done, but because my tests werewritten before I started coding the meat of a solution, I had (and continueto have) high condence that my program works and will continue to work(or alert me quickly to new errors) should I make any enhancementsdown the road. Geoffrey S. Knauth, 2011The main focus of this book is thedesign processthat leads from problem state-ments to well-organized solutions, oriented around the concept ofobjects. We makeextensive use of explicit design guidelines formulated as a numberprogram designrecipesas described inHow to Design Programs. The most general form of the recipefor designing programs is given in gure 1.1. Problem Analysis & Data Denition2. Contract, Purpose & Effect Statements, Header3. Examples4. Template5. Code6. TestsFigure 1: The Design Recipe for ProgramsThe objective of the design recipe is to provide atechniquethat guides programmers910CONTENTSnovices and professionals alikewith a systematic approach to problem solving. Byreasoning systematically, programmers can eliminate the incidental complexities ofwriting software and instead focus their creative energy on what is essentially difcultabout a particular problem. A great programmer is rst a master technician; they con-tinue to hone and internalize their skills with each day of programming. As the chefJacques Pépin said,2speaking of another eld that values the idea of recipes, to masterthe technique, you have no choice: you have to repeat, repeat, repeat, repeat until itbecomes part of yourself.2New York Times, There's the Wrong Way and Jacques Pepin's Way October 18, 2011.The Choice of Language andEnvironmentAnother lesson we should have learned from the recent past is that the de-velopment of richer or more powerful programming languages wasa mistake in the sense that these baroque monstrosities, these conglomer-ations of idiosyncrasies, are really unmanageable, both mechanically andmentally. I see a great future for very systematic and very modest pro-gramming languages. Edsger W. Dijkstra The Humble Programmer, Turing Award Lecture,1972In support of this book, we have a developed a series of modest programming lan-guages that emphasize the principles of object-oriented design. We use these languagesthroughout the rst part of the book. They are deliberately not industrial strength pro-gramming languages, complete with full-featured libraries, convenience mechanisms,and the usual idiosyncrasies that accompany real languages. Instead we have de-signed a progression of simple and consistent languages which embody the commoncore of modern object-oriented languages. The idea is that by focusing on the concep-tual basis of object-oriented programming, students can apply their design knowledgeregardless of whatever linguistic context they happen to nd themselves in down theroad.In the second part, we transition to Java, a widely used industrial language that hasbeen developed over more than 15 years. The move to Java allows us to explore theapplication of the principles introduced in the rst portion of the course in the contextof a practical language.As of this draft of the book, the course software has been developed and testedwith version 5.2 of Racket. To install the course software, you will rst need to installRacket:http://racket-lang.org/Once installed, launch DrRacket, the development environment that ships with theRacket system. Click on theFile|Install PLT File, and then enter the URL:http://www.ccs.neu.edu/course/cs2510h/class-system-latest.plt1112CONTENTSAfter the PLT le has been installed, selectLanguage|Choose Language...and se-lect the Use the language declared in the source option. You can now write programsin any of the languages included in the course software by writing#lang class/Nasthe rst line of a le, whereNis a number in0,1,2, etc. To nd out more about thelanguages, use Help Desk and search forclass/0to get started.The Parts of the Book1314CONTENTSAcknowledgmentsWe are grateful to Matthias Felleisen, our TAs: Daniel Brown (2011), Asumu Takikawa(2012), and Nicholas Labich(2013), our tutors: Alex Lee, Nikko Patten, Jim Shargo,Trevor Sontag (2011), Spencer Florence, Sarah Laplante, Ryan Plessner (2012), BeccaMacKenzie, and Kathleen Mullins (2013), and the Northeastern students we have hadthe privilege of teaching in 2011 and 2012.1516CONTENTSPart IBasic Design with Objects17Chapter 1Objects = Data + FunctionOne of the key concepts behind so-calledobject-oriented programming(OOP) is thenotion of anobject. An object is a new kind of value that can, as a rst cut, be under-stood as a pairing together of two familiar concepts: data and function.An object is like a structurein that it has a xed number of elds, thus an


View Full Document

NU CS 2510 - Designing Programs with Class

Documents in this Course
Runner

Runner

5 pages

Load more
Download Designing Programs with Class
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Designing Programs with Class and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Designing Programs with Class 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?