DOC PREVIEW
Purdue ECE 462 - Lecture notes

This preview shows page 1-2-20-21 out of 21 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 21 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 21 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 21 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 21 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 21 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

ECE 462Object-Oriented Programmingusing C++ and JavaLecture 23Yung-Hsiang [email protected] 14 2C++ History• why to study history? – Knowing the past often helps us plan for the future.– The design decisions of one programming language help us design better languages.• Since C++ (1982), many new programming languages have been developed:– 1991 Python– 1995 Java 1– 1995 PHP– 1997 OO COBOL–...week 14 3History of C++: 1979-1991by Bjarne Stroustrup• background– 1977 Apple 1 & 2 (1MHz processor, 4-48KB memory, $1300-$2600)– 1979 Intel 8088– 1980 Seagate (then called Shugart) 5.25-in 5MB disk– 1981 IBM PC (4.77MHz, 16-640KB memory) – 1983 TCP/IP• Computers were slow and expensive.week 14 4C++• design goals:– Simula's facilities for program organization– C's efficiency and flexibility– for system programming• 1979-1983 C with Classes• 1982-1985 C++• 1985-1988 C++ 2.0• 1988- standardization (ISO / ANSI)• ISO = International Organization for Standardization• ANSI = American National Standards Instituteweek 14 5Simula• simulator for a distributed system• class hierarchy • capturing type errors by compiler– type: int, string, Student, Computer ...– type error, for example, a Student object + 3, a Computer object+ "hello" ...• problem of Simula: link time too long– run-time type checking – variable initialization– garbage collection, even for a program without garbage⇒ performance too lowweek 14 6Programming Language Design• Never attack a problem with wrong tools.1. support for program organization: class, hierarchy, concurrency, static type checking2. good tools to compile files separately, to link files written in different languages, and to produce fast programs3. portable across different machines• His background in OS and communication affects many design decisions, such as model of protection and exception handling • A good language requires a good implementation. Performance matters.week 14 7C with Classes• new language developed to analyze UNIX kernel: analyze network traffic and modularize kernel⇒ develop an extension of C by adding tools⇒ Some programming languages are developed for specific purposes and then are generalized.• no primitives to express concurrency, use libraries instead (different from Java with built-in thread supports)– built-in support: consistent with language, but may cause unnecessary overhead to the users that do not need this feature– libraries: more flexibility but increase the overhead in system administration to ensure version compatibility• C with Classes to be used anywhere C is used ⇒ efficiencyrequirements eliminate built-in runtime safety checkingweek 14 8Features in C with Classes• "philosophy": language designers should not force programmers touse a particular style; instead, designers should provide styles, practices, and tools to help programmers avoid well known traps ⇒C allows low-level operations and type conversions, so does C with Classes• features (1980): class, derived class, public / private access, constructor / destructor, call and return, friend class, type checking and conversion of function arguments• features (1981): inline, default arguments, overloading of assignment operator• C with Classes was implemented as pre-processor of C ⇒ portable across machines ⇒ common approach for language design todayC with Classespre-processorCC compilerexecutableweek 14 9Design Decisions in C with Classes• A class is a type.• Local variables are allocated at stack, not heap ⇒ no need to call destructor or garbage collection• Default access control is private.• Static type checking for function arguments and return values.• Class declarations and function definitions can be in different files (different from Java). Hence, class declaration can be the "interface" (Java distinguishes interface from class)• "new" calls constructor (not all valid C programs are valid C++ programs)• Use-defined types (classes) are treated in the same way as the built-in types.• Function inlining is used to reduce the overhead of calls ⇒discourage programmers from declaring data members as public.week 14 10// classX.hclass X {public:void foo(int, float);};// both a class declaration and // interface// classX.cpp#include "classX.h”void X::foo(int a, float b) {...}// define the implementation of a // member functionweek 14 11Garbage Collection in C++• considered until 1985• inappropriate for a language (C) already had run-time memory management• GC would degrade performance unacceptably• Stroustrup stressed that there was no "grand plan" to develop C++. Hence, the usefulness of the language resided on the ability to attract users in Bell Lab by solving their problems, efficiently.week 14 121982 C++• C with Classes was a "medium success"• major features:– virtual function– function and operator overloading– reference– constant• virtual function– to adapt to similar but different (common base class) types– a large if-then-else or switch-case block is undesirable– dilemma: allow adaptability by users without allowing the changeof base classes (possibly from the library)week 14 13void shape::draw(){switch (type) {case circle:// draw a circlebreak;case square:// draw a squarebreak;case triangle:// draw a trianglebreak;}}week 14 141986 C++ 2.0• multiple inheritance, "the fundamental flaw in these arguments is that they take multiple inheritance far too seriously... it is quite cheap... you don't need it very often but when you do it is essential."• type-safe linkage• abstract class• static member functions• protected members• overloading ->• Exception handling was added later.week 14 15Summary• C++ was developed to solve a specific problem: simulating distributed systems• It is important to choose a good language as the base and build on top of the base; this can obtain immediate tool support.• Features do not have to be added at once. Most features are added out of necessity, as the basic functionalities are available.• Separate compilation and linking is critical for developing large-scale programs.• Performance is essential. Many design decisions are based on theimpact of performance.week 14 16Brief History of Java 1995-• started in 1991 and announced in 1995• Java started as a technology for entertainment "set-top box" to create a language that can run on small portable systems, not


View Full Document

Purdue ECE 462 - 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?