DOC PREVIEW
Stanford CS 106B - Lecture Notes

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Simple C++Evolution of Computer LanguagesSize and Complexity in LanguagesRelationship Between C and C++The March of ProgressEssential and Accidental ComplexityC++ vs. Java: Accidental DifferencesC++ vs. Java: Essential DifferencesThe “Hello World” ProgramTaxicab NumbersThe EndSimple C++Eric RobertsCS 106BApril 3, 2009Evolution of Computer LanguagesSize and Complexity in LanguagesRelationship Between C and C++The March of Progress266 pages274 pages911 pages1536 pagesEssential and Accidental ComplexityTo see what rate of progress one can expect in software technology, let us examine the difficulties of that technology. Following Aristotle, I divide them into essence, the difficulties inherent in the nature of software, and accidents, those difficulties that today attend its production but are not inherent. . . .Fred Brooks“No Silver Bullet”IEEE Computer, April 1987—The complexity of software is an essential property not an accidental one. Hence, descriptions of a software entity that abstract away its complexity often abstract away its essence.C++ vs. Java: Accidental Differences•The type of Boolean variables is bool instead of boolean.•The type char represents an 8-bit ASCII character instead of a 16-bit Unicode character.•Programs in C++ begin by calling a function named main that returns an integer status, which is 0 on successful completion.•All functions used in a C++ program must be preceded by a prototype that defines their parameter structure.•There are many accidental differences in the methods exported by the string class. For example, the second argument to the C++ substr method is the length and not the ending position.•The discipline used for console I/O is significantly different, but not essentially so.C++ vs. Java: Essential Differences•C++ allows you to get very close to the inner workings of the machine. Java protects you from these details.•C++ supports call by reference.•C++ allows programmers to modify the language in more ways than Java does. In particular, a C++ class can redefine the meaning of operators such as + or <<.•C++ has no garbage collector of the sort that Java does. As a result, you are responsible for freeing any memory that is allocated on the heap.•Objects in Java are always allocated in the heap. In C++, objects are typically stored on the stack to simplify the task of memory management.•C++ supports multiple inheritance, which means that classes can inherit behavior from more than one superclass.The “Hello World” ProgramOne of the important influences on the design of Java was the C programming language, which was developed at Bell Labs in the early 1970s. The primary reference manual for C was written by Brian Kernighan and Dennis Ritchie.On the first page of their book, the authors suggest that the first step in learning any language is to write a simple program that prints the message “hello, world” on the display. That advice remains sound today.1.1 Getting Started The only way to learn a new programming language is to write programs in it. The first program to write is the same for all languages: Print the words hello, worldThis is the big hurdle; to leap over it you have to be able to create the program text somewhere, compile it, load it, run it, and find out where your output went. With these mechanical details mastered, everything else is comparatively easy. In C, the program to print “hello, world” is #include <stdio.h> main() { printf("hello, world"); }Taxicab NumbersThe


View Full Document

Stanford CS 106B - Lecture Notes

Download Lecture Notes
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 Lecture Notes 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 Lecture Notes 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?