lecture31-apr16 - 4/16/10 Lecture 31 Announcements...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
4/16/10 1 Lecture 31 Announcements • Assignment 6 – Due next Thursday; Q&A CodedText.bin file on the BB was fixed • Topics of the day – Start C++ EfFciency of C One of C’s strengths is the ability it gives programmers to write efficient programs. The right way to achieve efficiency: – Focus on choosing the right algorithms and data structures. – Use a profiler (timer) to find the program’s “hot spots”— sections of code that consume most of the program’s running time. – Once the hot spots have been identified, rewrite them for greater efficiency. The wrong way to achieve efficiency: – Condense code as much as possible. The gains from “micro-optimization” are small at best (perhaps a few percent) and are often offset by a decrease in readability and modifiability. Many of today’s compilers routinely perform the sort of optimizations that programmers used to do by hand. There’s nothing wrong with making code shorter; just be sure that the primary goal is clarity, not efficiency. What’s Wrong with C ? • It’s really a middle level language • Its not strongly typed • Its not machine independent • It has little run time error checking • Not block structured, but is function based • It does not support OOP • It places few restrictions on programmers • It has no graphical programming capability • Lots of other little nits that are annoying • It does not easily support certain key software engineering concepts; e.g. abstract data types – Programmers have attempted various strategies for implementing abstract data types in C, but most involve confusing preprocessor tricks. Where C++ ±its C Std C (c89) C99 C++ Geneology of C C++ Std C (c89) These are very different Abstract Data Types • A module that encapsulates a data structure has one disadvantage: there’s no good way to have multiple instances of the data structure. • To accomplish this, we need a new data type; the users of the module can then define several variables of that type. • When the details of a type’s implementation are hidden from the users of that type, it’s called an abstract data type (ADT) . • The most effective way to solve the problem of defining abstract data types is to use C++. • C++ allows the definition of classes , which resemble structures in C, except that: – classes may contain functions as well as data. – parts (aka, members ) of a class may be hidden from the rest of the program (information hiding). – classes are used to create multiple objects of that type Abstract Data Type the ADT would be of your own design and would work like the built-in types of the language Interface to the ADT
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4/16/10 2 Introduction to C++ • Invented in the 1980’s to support modern programming principles - e.g. abstract data types • It
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

lecture31-apr16 - 4/16/10 Lecture 31 Announcements...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online