1 / 17

EECS 231

EECS 231. ADVANCED PROGRAMMING. Staff. Instructor Vana Doufexi vdoufexi@cs.northwestern.edu Ford Building, 2133 Sheridan, #2-229 Teaching Assistant TBA. Class resources. Webpage http://www.cs.northwestern.edu/~vdoufexi/231 Use it to: download class notes, handouts and assignments

Download Presentation

EECS 231

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EECS 231 ADVANCED PROGRAMMING

  2. Staff • Instructor • Vana Doufexi • vdoufexi@cs.northwestern.edu • Ford Building, 2133 Sheridan, #2-229 • Teaching Assistant • TBA

  3. Class resources • Webpage • http://www.cs.northwestern.edu/~vdoufexi/231 • Use it to: • download class notes, handouts and assignments • look up your grades • look up class policies • Newsgroup • newsgroup name: eecs.231 • nntp server: news.cs.northwestern.edu • Use it to • check announcements • discuss class material • discuss assignments (but NEVER post solutions)

  4. Goals • Learn how to design a project (using OOD) • Learn C++ • Learn how to write clear, well-designed code • Learn how to test and debug efficiently • Get familiar with development on Unix systems

  5. Object-oriented design • Main idea: • Model the problem as a collection of objects that have certain attributes and interact with one another and the world. • Example: • Simulating a transportation company that owns trucks and trains. • objects (nouns) : truck, train • attributes : load, capacity, speed, destination, etc. • operations (verbs) : unload, fill up, travel, etc. • How about the network of assembly plants, depots, dealerships?

  6. Concept: Abstraction • Main idea: • Focus on the essential details about an entity and consequently on the common elements between entities. • Example: • Our simulator may consist of a large class of objects called Vehicle. All vehicles share some attributes (e.g. load, capacity) and specific operations may be applied to them (e.g. unload, move_to_destination). • There may be several levels of abstraction, each with more detail that the previous level: the Vehicle class consists of two subclasses of objects, the Truck and the Train. Each subclass has its own attributes and operations, specific to it, in addition to the common ones.

  7. Concept: Abstraction • Big advantages: • It enables us to present a general interface, hiding implementation details. • It makes it easier to add new types of objects (e.g. Ship as a subclass of Vehicle, Tanker and Car-ferry as subclasses of Ship) Vehicle Three levels of abstraction Ship Truck Train Tanker Car ferry

  8. Concept: Reuse • Example 2: • In what way is a network of warehouses different from or the same as a network of cities used by an airliner? • If we already have the abstract design of the airliner's network, can we use that as the basis of our transportation network? • Main idea: • Use previously designed software in a new application • Big advantages: • Less development time (and as a result, less cost) • More reliable product (the software you are reusing has been tested extensively)

  9. Concept: Encapsulation • Main idea: • Group data together with the operations that can be performed on it and provide a public interface that controls how the data can be used/modified. • Big advantages: • The object can be modified only though its interface.There are no dangerous dependencies between unrelated components.

  10. Concept: Information hiding • Main idea: • Hide information about a module's structure and implementation from other modules that don't need this information. • Big advantages: • Other modules are not concerned with the internal design. • Example: You don't need to know how the engine works to drive a car. • We may modify the implementation without having to modify the way the module interacts with other modules • Example: If the "implementation" of the engine changes (e.g. to a diesel engine), the interface (steering wheel, gas pedal, gear box, etc) remains the same.

  11. Concept: Maintainability • Main idea: • Make your program easy to modify in order to correct faults, or adapt it to a changed environments, or improve performance. • Abstraction, information hiding, modularity enhance the maintainability of your code. • In addition, you should always write clear, readable and easily understandable code.

  12. Concept: Readability • Main issues: • Code formatting (the physical layout of your code) • Horizontal and vertical spacing, indentation, line length • Naming of identifiers (variables, function names) • Use clear, descriptive names. • Use nouns for variables, verbs for functions. • Avoid shorthand. • Comments • Describe the intent of the programmer • good example: convert dollars to euros • bad example: multiply by 1.2 • BE CONSISTENT! • Do not mix up naming and formatting styles.

  13. The compilation process • Stage 1: Lexical analysis • The compiler identifies individual "tokens" such as identifier names, strings, plus signs, numbers, comments, etc. • Errors discovered: unterminated comments/strings, unrecognized symbols. • Stage 2: Syntax analysis • The compiler identifies the structure of the program and checks whether it satisfies the syntactic rules of the language. • Errors discovered: syntax errors, such as missing semi-colons.

  14. The compilation process • Stage 3: Semantic analysis • The compiler identifies the meaning of the program, collects information such as types of variables and performs tests such as type checks. • Errors discovered: type errors (e.g. trying to assign a number to a string variable). • Stage 4: Code generation • The compiler generates object code. • (We have skipped a couple of stages that are not important to this discussion)

  15. The compilation process • Stage 5: Linking • The linker combines one or more files containing object code from separately compiled program modules into a single file containing executable code. • Errors discovered: missing libraries • Finally: Execution • The program can now be executed. • Errors discovered: run-time errors are caused when your program tries an operation that is not allowed (e.g. when it tries to access a part of memory that it shouldn't). These are not caught by the compiler and are the most difficult to identify and solve. This is where good debugging practices are needed.

  16. Debugging • Often the most time consuming stage of the developing process. • It must be performed in a systematic way. • BAD! : Let's try to change this line, to see if it fixes the problem. • GOOD! : Let's use the debugger. • The debugger can show you what happens inside your program as the latter executes. It allows you to • execute your program line by line, • make your program stop at a specific point or when a certain condition is satisfied, • check the value of an expression at some point.

  17. Elements of Programming Languages • Variables and types • Expressions • Assignments • Control flow constructs • Statements • Functions

More Related