(logo) erlkönig:
modular & object- oriented programming

instructorC. Alex. North-Keys
environmentUnix/GNU
prototypefirst taught to designer/programmers from Origin Systems

This syllabus is subject to continuing evolution Although the thrust of the class will remain substantively identical, details, exercises, examples, etc, are all subject to change, both instructor- and student-initiated.

This class has been prototyped for six four-hour sessions, spread over eight days, and should not be compressed (ie: fewer days, more hours per day), although spreading it over seven sessions might well be ideal. One break will be given in the middle of each class. Pagers and the like are deprecated - there will not be time to answer calls.

This class requires acculturalization to programming as a prerequisite. Some direct experience in computer programming is strongly recommended. The prototype class is being taught in the industry-standard cave-mode, replete with low-level multisource incandescent lighting, anti-formal clothing, and ubiquitous use of computing's native jargon.

SessionDayTopics
1Monday
  • source code
  • object code
  • writing a program from scratch
2Tuesday
  • preprocessing
  • data representation and simple variables
  • algorithmic programming
3Thursday
  • arrays of structures
  • dynamic memory allocation, vectors
  • functional decomposition
4Friday
  • modular programming and libraries, matrices
  • object-oriented programming - C
5Monday
  • object-oriented programming - C++
  • focus: construction/destruction and overloading
6Tuesday
  • object-oriented programming
  • focus: inheritance and polymorphism
  1. source code

    1. the single sourcefile

      1. filename extensions .c .c++ .C .cc .cxx .cpp .h .H .hh
      2. comments and administrative information
      3. human-readable text in sourcecode
      4. students look for illuminating comments in source code and human-readable strings in the sourcecode
      5. compiling a single sourcefile

        1. relationship of source code to object code
        2. compiling a source file
        3. students compile a sourcefile with gcc
        4. running the resulting program
        5. students look for any output matching the strings found in the source.
      6. #included files
      7. user-defined types, constants, variables, and functions
      8. viewing a source file as a declaration list
      9. the significance of the function called main
      10. students identify major parts of source files
    2. more detail about the compilation process

      1. preprocessing cpp
      2. compilation gcc and g++
      3. assembly as
      4. linking ld
      5. students compile a program using incremental commands, looking at the results of each painful step along the way
      6. runtime dynamic loading ld.so
    3. multifile compilation

      1. sharing variables and functions between object modules
      2. safer sharing through prototypes
      3. students identify inter-file constructions in their native habitat
      4. multi-sourcefile software packages
      5. the multifile compilation process
      6. students enjoy compiling a multifile program without the assistance of more advanced utilities
    4. automating the compilation process

      1. file timestamps and dependency checking
      2. the make utility and simple Makefiles
      3. students write and use a simple makefile to compile both a simple and a multifile program
      4. a brief discussion of targets and pattern rules
  2. object code

    1. digging around in the object file

      1. machine language and architecture-dependency
      2. viewing raw machine code with less and odump
      3. digging out text with strings -
      4. looking at the namelist with nm
      5. students eviscerate the object file and look at the mess
      6. magic numbers and finding file types with file
    2. libraries

      1. the purpose of object libraries
      2. static libraries

        1. how static libraries work
        2. constructing .a archive libraries with ar
        3. linking against a static library at compilation
        4. library independency
      3. dynamic libraries

        1. how dynamic libraries work
        2. constructing .so shared object libraries
        3. linking against a static library at runtime
        4. checking library dependencies with ldd or elfdump -Dl
        5. finding dynamic libraries
      4. feature comparison of static and dynamic linking

        1. executable size differences
        2. dynamic upgradability
        3. dependency on shared library functionality
        4. program load times
      5. the namelist of a library
  3. writing a small program from scratch

    1. creating your source files

      1. choosing a program name not already in use
      2. creating a directory for your sourcecode
      3. the Hello World programming koan
      4. using an editor to input the source
      5. students use system utilities to enter the source code for this perennial favorite first program
    2. getting your program to compile

      1. step-by-step compilation with cpp gcc as ld
      2. students compile the program the painful, slow, and error-prone way
      3. using the compiler as a front end
      4. students compile the program the hard way, with the -v option to see how much worse it could be (ie. the way the did it last time, but much more arcane)
      5. using automation
      6. students compile the program the easy way using make
    3. dissection and vivisection of your program

      1. using nm and strings
      2. students dig around in their compiled program looking for characteristic things in the binary they recognize from the source
      3. using trace (by whatever name) on a running program
      4. debuggers and how to compile to enable them
      5. students recompile their program with the -g option and step through the program in the gdb debugger
    4. the preprocessor

      1. the role of C preprocessor: cpp
      2. preprocessor constants with #define
      3. students run the preprocessor on a sourcefile with an abundance of preprocessor syntactic sugar/saccharine
      4. comparison with enumerated constants enum
      5. students convert a program from preprocessor constants to enumerations
      6. preprocessor macros with #define to escape C language constraints
        #ifdef      DEBUG
        #   undef   DEBUG
        #   define  DEBUG(b)    do{b}while(0)
        #   define  IFDEBUG(b)  if(Debug)do{b}while(0)
        #else  /* ! DEBUG */
        #   define  DEBUG(b)
        #   define  IFDEBUG(b)
        #endif /* ! DEBUG */
        
        #define method(t,n,d)\
        char * ## n ## _doc = d;\
        t n
        #define manner(n) n ## _doc
        
        #define ever ;;
        				
      7. students run the preprocessor on some examples
      8. preprocessor namespace collisions
  4. data representation

    1. data encoding in memory

      1. methodologies for storing data on a computer
      2. a brief overview of other bases
      3. students do long multiplication in some foreign bases
      4. encoding numeric data

        1. data sizes, with special reference to integers
        2. byte-ordering and the resulting portability nightmare
        3. students compare values of an two-byte integer being transmitted between a big-endian and little-endian machine
        4. floating point
        5. arrays
        6. C language syntax for numerics
          1. named integer constants with: enum
          2. integer and floating point syntax
          3. subscript notation and declaration of arrays
      5. encoding non-numeric data

        1. characters
        2. character strings in ASCII, ISO-8869-1, and Unicode
        3. C language syntax for non-numerics
          1. character data, single quote, and escape sequences
          2. string data in double quotes
          3. relationship of string declaration to array declaration
          4. students run code demonstrating the string-to-array congruency
    2. data encoding for storage

      1. raw binary files
      2. byte-ordering problems, revisited
      3. human readability
      4. robust and fragile grammars
  5. Variables

    1. simple types

      1. integral types: char int
      2. floating types: float double
      3. variations: short long signed unsigned
      4. determining the size of basic data types with sizeof
      5. students examine, compile, and run a program to enumerate the sizes of the integral and floating types
    2. compound types

      1. structures (like records in Pascal): struct
      2. unions, allowing member overlap: union
      3. classes, with member functions: class
    3. other aspects of types and variables

      1. user-defined types: typedef
      2. variables defined in other files: extern
      3. weird variables: const volatile
    4. derived types

      1. pointers
      2. vectors and matrixes (vs. arrays)
  6. algorithmic programming

    1. flow of control

      1. jumps: goto switch case default break
      2. selections: if else
      3. loops: for while do-while continue break
      4. students write programs to demonstrate looping constructs by counting
      5. functions: calls and return
      6. single character input using wgetch under curses.
      7. students write programs demonstrating election-terminated loops, switches on input, bounds checking and use of the curses library (x, bounce).
    2. input and output

      1. output by chars, strings, formatted data, and file output
      2. input by the same measures
      3. intractability of human input (special note of fscanf)
  7. functional decomposition

    1. declaring and defining functions

      1. the abstract of pure functions vs. procedures
      2. students rewrite an earlier program (possibly the loop demo program) using procedures
      3. function return types
      4. how to declare arguments
      5. students rewrite an earlier program (possibly the bounce program) using functions
      6. the four ways function names occur in source
        1. declaration - return type, parens, and empty body
        2. definition - return type, parens, and full body
        3. use - no return type (unless cast), parens, no body
        4. address - no type, parens, or body
      7. function prototypes
      8. students create prototype lists for the newly enfunctioned program
      9. variable argument lists
      10. students are exposed to a vararg summing function
      11. recursion, and comparison vs. iteration
      12. students are exposed to a recursive power function
      13. function pointers (C)
      14. students are exposed to function pointers enabling operator parameterization
    2. memory management

      1. stack, data, and text segments of a program
      2. sbrk and malloc
      3. malloc
      4. realloc
      5. free
      6. students rewrite the bounce program to use dynamic memory (re)allocation
      7. garbage collection
  8. modular programming

    1. code reuse and related issues
    2. namespaces and namespace clutter
    3. variables' lifetimes

      1. scope global: dangers of global data
      2. scope local: variable hiding
      3. scope file: function hiding
      4. automatic variables: auto
      5. static and other globals
      6. persistent data - benefits and pitfalls
      7. reëtrancy and auto variables
    4. interfaces to function collections
    5. modules and libraries
    6. compilation unit internals and replaceability
  9. object oriented programming

    1. object candidacy in the problem domain
    2. object basics
    3. operator overloading

      1. viewing an operator as just another function
      2. C++ i/o methods with cin cout cerr clog and << >>
    4. object-orientedness in C with typedef

      1. the new/delete idiom in C
        typedef struct _Thing { ... } Thing;
        Thing *ThingNew(void);
        Thing *ThingDelete(Thing *doomed);
        void   ThingAction(Thing *t);
        int    ThingFout(Thing *t, FILE *out);  /* FILE still used in C */
        			
      2. students are subjected to object-orientedness in C, via a tour through an example program for running the life cellular automaton
    5. classes

      1. the class new/delete idiom in C++
        class Thing {
           Thing();
           ~Thing();
           void Action();
           int ThingFout(FILE *out);  // although FILE is unusual in C++
        };
        			
      2. comparison to typedef Thing with ThingNew and ThingDelete, etc.
      3. automatic constructors and destructors
      4. students convert an earlier C program demonstrating the ThingNew/ThingDelete idiom into the equivalent C++
    6. orthodox canonical class form

      1. default constructor X::X()
      2. copy constructor X::X(const X&)
      3. assignment operator X& operator=(const X&)
      4. destructor X::~X()
    7. access control

      1. public:
      2. protected:
      3. private:
      4. allowing specific access: friend
    8. object and class relationships

      1. IS-A
      2. HAS-A
      3. USES-A
      4. CREATES-A
      5. LIKE-A
    9. inheritance

      1. simple inheritance
      2. students derive new object types with a demonstration program
      3. virtual functions and abstract base classes
      4. signatures
      5. polymorphism
      6. students study a window-system-polymorphic example program
    10. further discussion

      1. templates
      2. envelope/letter paradigm - representing numbers
      3. exemplars and the ->make() idiom

suggested reading

Author/sTitleISBNYear
Ellis/Stroustrup The Annotated C++ Reference Manual 0-201-51459-1 1990
James O. Coplien Advanced C++ Programming Styles and Idioms 0-201-54855-0 1992
Valid XHTML 1.1! Valid CSS!