Themes and Ideas in Prog. Lang - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Themes and Ideas in Prog. Lang

Description:

Divide a program into comprehensible pieces ... Smalltalk - everything's an object. CLOS - Common Lisp with object system added ... – PowerPoint PPT presentation

Number of Views:60
Avg rating:3.0/5.0
Slides: 28
Provided by: bobma5
Category:

less

Transcript and Presenter's Notes

Title: Themes and Ideas in Prog. Lang


1
Themes and Ideas in Prog. Langs
  • Divide a program into comprehensible
    pieces(subprograms, types, declarations,
    objects, packages, threads, tasks) (control
    changes)
  • Pieces communicate with each other(development
    (names), construction (linking), and execution
    times (parameter passing, named and positional),
    self describing data)
  • Types as values with operations type handling,
    generics/templates
  • Encapsulated objects object extension, classes
  • Components, reuse

2
Data Types Modules Objects
  • FORTRAN data is numbers, procedures
    algorithms whats important and complicated
  • COBOL lots of data but processing simple
  • FORTRAN ALGOL procedural
  • But not all problems are like that
  • Other approaches to programming(for example,
    functional declarative)
  • Maybe more complicated processing can be based on
    data and events (events as objects)
  • Object-oriented programming

3
Break Program into Parts
  • Understandable size
  • Just some number of lines seems inappropriate
  • Organizational criteria
  • GOTO off page connector problems
  • Subprograms (yes, but not quite right)
  • Module
  • Collection of related subprograms and other
    information about a part of program
  • Criteria?
  • Information/decision hiding

4
Information Hiding in Modules
  • Collect typing information, constants, data
    formats, variable locations, implementation of
    subprograms, and anything else that might relate
    to design decision that doesnt need to be known
    by rest of program
  • Hide information about implementation
  • Is stack implemented with array or linked list?
  • Is output device made by IBM or Apple?
  • Abstract data types
  • Potential values and operations

5
Big Building Blocks
  • Subprograms are too small a unit
  • Subprograms small for understandability
  • Need a bigger grouping unit
  • Ada packages (Pascal units)
  • Way of grouping related declarations(data types,
    subprograms, constants, variables)
  • Ada task types have similar role, but independent
    threads of execution were heavyweight in 1980
  • C - classes
  • Need other grouping mechanisms beyond objects

6
Visibility
  • Another problem is who could change
  • Visibility is control compiler enforces
  • Information is not really hidden, the compiler
    mainly enforces you dont use your knowledge
  • Knowing the implementation necessary for code
    generation and efficient programming, but want
    compiler to check what you use
  • Implement stack on array, but dont allow direct
    subscript manipulation or member reference
  • Interface

7
Separate Interface
  • Specify the interface others can use to access
    information you want to make available (while
    hiding something else)
  • How to get next element
  • How to add to stack
  • How big is stack
  • But not what pointer value is to third element
  • Problems with C / C
  • Header not always required nor type checked
  • Limited visibility control

8
Programming with Interfaces
  • Determine interfaces between modules
  • Program on either side to that interface
  • Problems resolved in terms of redefining
    interface (clean separation, no ad hoc fixes)
  • Requires interfaces be part of language
  • Ada package, subprogram task specifications
  • Ada incomplete type declarations private
  • C / C headers
  • Java interface
  • CORBA Interface Definition Language (IDL)

9
Review of Big Ideas
  • Programming with interfaces
  • Getting others to cooperate in doing the work
    delegation
  • specify boundaries
  • give flexibility to work within
  • Calling a subprogram
  • You know what its going to do (specification)
  • but dont care how (implementation)

10
Factorial (1..6)
  • int factorial(int n) if (nlt1) return 1
    else return nfactorial(n-1)
  • int factorial(int n) if (nlt1) return 1
    else if (2n) return 2 else if (3n)
    return 6 else if (4n) return 24 else if
    (5n) return 120 else if (6n) return
    720..
  • int factorial(int n) int resultfor (result1
    ngt1 n--) result nreturn result

11
Major Themes in Prog. Langs
  • divide a program into comprehensible
    pieces(subprograms, types, declarations,
    objects, packages, threads, tasks)(control
    whats changed where)
  • pieces communicate with each other(development
    (names), construction (linking), and execution
    times (parameter passing, named and positional),
    self describing data)
  • combine the pieces (loaders, linkers, build
    scripts, registries (of names), installers)
  • adapt to the underlying execution environment
    (code generation, APIs (Application Program
    Interfaces), distributed code, CORBA, operating
    systems, optimizations, garbage)

12
Breakthrough Ideas in Prog. Langs
  • Types as values with operations(abstract data
    types)parameterized types (generics/templates)
  • Language extensibility, macros, parameterized
    extensions, patterns
  • Modularity, packages, environments, separate
    specifications/interfaces
  • Encapsulated (visibility and change control)
    objects and object extension, classes
  • Components, reuse

13
Modules Types Objects
  • Were just started
  • Chapter 6 Data Types
  • Mostly discussed before

14
Pointer Types (Sebesta 5)
  • Reference Types
  • Java references refer to class instances(all
    class instances referenced by reference
    variables)(only use of reference variables)
  • no pointer arithmetic
  • Evaluation
  • does Java provide sufficient safety with
    sufficient flexibility
  • Heap Management
  • garbage collectioneager (generation), lazy
    (wait till needed)
  • plentiful (virtual) memory not useful in all
    situations

15
Abstract Data Types
  • The Concept of Abstraction
  • managing/understanding complexity
  • subprograms, functions, special notations
  • lemmas - theorems corollaries
  • process abstraction
  • data (type) abstraction
  • "An abstract data type, simply put, is an
    encapsulation that includes only the data
    representation of one specific data type and the
    subprograms that provide the operations for that
    type."

16
Encapsulation
  • modularization - separating a large
    problem/program into sections/modules
  • intellectually manageable
  • separate compilation
  • Encapsulation syntactic mechanism in the
    language so compiler tools can help
  • "Through access control, unnecessary details of
    the type can be hidden from units outside the
    encapsulation that use the type."
  • instance - object

17
Object-Oriented Prog.
  • Introduction
  • encapsulation (abstract data types)
  • inheritance
  • dynamic dispatching (binding)
  • Procedure-oriented programming (send the work to
    the workers) vs.Data-oriented programming (have
    the workers move from thing to thing)
  • Composition, delegation
  • Programming with interfaces

18
Inheritance
  • Doing my taxes, daughters taxes
  • Food examples

19
From Max Ermas Su07
20
Object-Oriented Prog. - 2
  • Inheritance
  • motivated by software reuse
  • without wanting to modify existing code
  • abstract data types
  • classes (objects are instances of classes)
  • derived through inheritance - derived class or
    subclass(other way is parent or super class)
  • methods (instead of procedures or functions)
  • visible message interface of object - message
    protocol
  • subclasses can override inherited version of
    methods
  • instance methods and variables vs. class (wide)
    methods and variables
  • single vs. multiple inheritance

21
Object-Oriented Progr. -3
  • Polymorphism and Dynamic Binding
  • case/switch inside a function changed to provide
    new functionality
  • dynamic binding/dispatch of overloaded functions
  • abstract/virtual method/class - interface without
    implementation
  • Computing with an Object-Oriented Language
  • simulation of solution approach to program
    development

22
Design Issues
  • Exclusivity of Objects
  • Smalltalk - everything's an object
  • CLOS - Common Lisp with object system added
  • Ada95, C - imperative with object-oriented
    support added
  • Java - objects except for primitive scalar types,
    wrappers
  • C syntax hides differences (box / unbox)
  • Are Subclasses Subtypes?
  • subclasses have all fields and methods of parent
    (not obvious)
  • Yes in Ada Java no in C

23
Design Issues
  • Implementation and Interface Inheritance
  • interface inheritance(only interface of parent
    available to children)
  • implementation inheritance(implementation
    details also visible)
  • dependencies vs. efficiency
  • language techniques for controlling visibility
  • Type Checking and Polymorphism
  • Single and Multiple Inheritance
  • Allocation and Deallocation of Objects
  • Dynamic and Static Binding

24
Overview of Smalltalk
  • General Characteristics
  • The Smalltalk Environment
  • Introduction to Smalltalk
  • Smalltalk Example Programs
  • A Simple Table Handler
  • LOGO-Style Graphics
  • Large-Scale Features of Smalltalk
  • Type Checking and Polymorphism
  • Inheritance
  • Evaluation of Smalltalk

25
Java (C, Ada95, Eiffel)
  • Java
  • Inheritance
  • Dynamic Binding
  • C method must be declared virtual to allow
    dynamic binding
  • Java - dynamic unless declared final (can't be
    overridden/extended so static)
  • Encapsulation
  • C
  • Ada 95
  • Eiffel
  • C

26
Return to Background Motivation
  • Program design trend understandability
  • Managing complexity of large programs
  • Controlling how program changes made
  • Controlling how program changes memory
  • Visibility control so compiler can help check for
    errors in use

27
UML for O-O Program Design
  • Unified Modeling Language
Write a Comment
User Comments (0)
About PowerShow.com