erlkönig:
modular & object- oriented programming
instructor | C. Alex. North-Keys |
environment | Unix/GNU |
prototype | first 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.
Session | Day | Topics |
1 | Monday |
- source code
- object code
- writing a program from scratch
|
2 | Tuesday |
- preprocessing
- data representation and simple variables
- algorithmic programming
|
3 | Thursday |
- arrays of structures
- dynamic memory allocation, vectors
- functional decomposition
|
4 | Friday |
- modular programming and libraries, matrices
- object-oriented programming - C
|
5 | Monday |
- object-oriented programming - C++
- focus: construction/destruction and overloading
|
6 | Tuesday |
- object-oriented programming
- focus: inheritance and polymorphism
|
source code
the single sourcefile
- filename extensions .c .c++ .C .cc .cxx .cpp .h .H .hh
- comments and administrative information
- human-readable text in sourcecode
-
students look for illuminating comments in source code
and human-readable strings in the sourcecode
compiling a single sourcefile
- relationship of source code to object code
- compiling a source file
-
students compile a sourcefile with gcc
- running the resulting program
-
students look for any output matching the strings
found in the source.
- #included files
- user-defined types, constants, variables, and functions
- viewing a source file as a declaration list
- the significance of the function called main
-
students identify major parts of source files
more detail about the compilation process
- preprocessing cpp
- compilation gcc and g++
- assembly as
- linking ld
-
students compile a program using incremental commands,
looking at the results of each painful step along
the way
- runtime dynamic loading ld.so
multifile compilation
- sharing variables and functions between object modules
- safer sharing through prototypes
-
students identify inter-file constructions in their
native habitat
- multi-sourcefile software packages
- the multifile compilation process
-
students enjoy compiling a multifile program without
the assistance of more advanced utilities
automating the compilation process
- file timestamps and dependency checking
- the make utility and simple Makefiles
-
students write and use a simple makefile to compile
both a simple and a multifile program
- a brief discussion of targets and pattern rules
object code
digging around in the object file
- machine language and architecture-dependency
- viewing raw machine code with less and odump
- digging out text with strings -
- looking at the namelist with nm
-
students eviscerate the object file
and look at the mess
- magic numbers and finding file types with file
libraries
- the purpose of object libraries
static libraries
- how static libraries work
- constructing .a archive libraries with ar
- linking against a static library at compilation
- library independency
dynamic libraries
- how dynamic libraries work
- constructing .so shared object libraries
- linking against a static library at runtime
- checking library dependencies with
ldd or elfdump -Dl
- finding dynamic libraries
feature comparison of static and dynamic linking
- executable size differences
- dynamic upgradability
- dependency on shared library functionality
- program load times
- the namelist of a library
writing a small program from scratch
creating your source files
- choosing a program name not already in use
- creating a directory for your sourcecode
- the Hello World programming koan
- using an editor to input the source
-
students use system utilities to enter the source code
for this perennial favorite first program
getting your program to compile
- step-by-step compilation with cpp gcc as ld
-
students compile the program the painful, slow, and
error-prone way
- using the compiler as a front end
-
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)
- using automation
-
students compile the program the easy way using make
dissection and vivisection of your program
- using nm and strings
-
students dig around in their compiled program looking
for characteristic things in the binary they recognize
from the source
- using trace (by whatever name) on a running program
- debuggers and how to compile to enable them
-
students recompile their program with the -g option
and step through the program in the gdb debugger
the preprocessor
- the role of C preprocessor: cpp
- preprocessor constants with #define
-
students run the preprocessor on a sourcefile with
an abundance of preprocessor syntactic sugar/saccharine
- comparison with enumerated constants enum
-
students convert a program from preprocessor constants
to enumerations
- 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 ;;
-
students run the preprocessor on some examples
- preprocessor namespace collisions
data representation
data encoding in memory
- methodologies for storing data on a computer
- a brief overview of other bases
-
students do long multiplication in some foreign bases
encoding numeric data
- data sizes, with special reference to integers
- byte-ordering and the resulting portability nightmare
-
students compare values of an two-byte integer being
transmitted between a big-endian and little-endian
machine
- floating point
- arrays
C language syntax for numerics
- named integer constants with: enum
- integer and floating point syntax
- subscript notation and declaration of arrays
encoding non-numeric data
- characters
- character strings in ASCII, ISO-8869-1, and Unicode
C language syntax for non-numerics
- character data, single quote, and escape sequences
- string data in double quotes
- relationship of string declaration to array declaration
-
students run code demonstrating the string-to-array
congruency
data encoding for storage
- raw binary files
- byte-ordering problems, revisited
- human readability
- robust and fragile grammars
Variables
simple types
- integral types: char int
- floating types: float double
- variations: short long signed unsigned
- determining the size of basic data types with sizeof
-
students examine, compile, and run a program
to enumerate the sizes of the integral and floating types
compound types
- structures (like records in Pascal): struct
- unions, allowing member overlap: union
- classes, with member functions: class
other aspects of types and variables
- user-defined types: typedef
- variables defined in other files: extern
- weird variables: const volatile
derived types
- pointers
- vectors and matrixes (vs. arrays)
algorithmic programming
flow of control
- jumps: goto switch case default break
- selections: if else
- loops: for while do-while continue break
-
students write programs to demonstrate looping constructs
by counting
- functions: calls and return
- single character input using wgetch under
curses.
-
students write programs demonstrating election-terminated
loops, switches on input, bounds checking and use of the
curses library (x, bounce).
input and output
- output by chars, strings, formatted data, and file output
- input by the same measures
- intractability of human input (special note of fscanf)
functional decomposition
declaring and defining functions
- the abstract of pure functions vs. procedures
-
students rewrite an earlier program (possibly the
loop demo program) using procedures
- function return types
- how to declare arguments
-
students rewrite an earlier program (possibly the
bounce program) using functions
- the four ways function names occur in source
- declaration - return type, parens, and empty body
- definition - return type, parens, and full body
- use - no return type (unless cast), parens, no body
- address - no type, parens, or body
- function prototypes
-
students create prototype lists for the newly enfunctioned
program
- variable argument lists
-
students are exposed to a vararg summing function
- recursion, and comparison vs. iteration
-
students are exposed to a recursive power function
- function pointers (C)
-
students are exposed to function pointers enabling
operator parameterization
memory management
- stack, data, and text segments of a program
- sbrk and malloc
- malloc
- realloc
- free
-
students rewrite the bounce program
to use dynamic memory (re)allocation
- garbage collection
modular programming
- code reuse and related issues
- namespaces and namespace clutter
variables' lifetimes
- scope global: dangers of global data
- scope local: variable hiding
- scope file: function hiding
- automatic variables: auto
- static and other globals
- persistent data - benefits and pitfalls
- reëtrancy and auto variables
- interfaces to function collections
- modules and libraries
- compilation unit internals and replaceability
object oriented programming
- object candidacy in the problem domain
- object basics
operator overloading
- viewing an operator as just another function
- C++ i/o methods with cin cout cerr clog
and << >>
object-orientedness in C with typedef
- 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 */
-
students are subjected to object-orientedness in C,
via a tour through an example program for running
the life cellular automaton
classes
- the class new/delete idiom in C++
class Thing {
Thing();
~Thing();
void Action();
int ThingFout(FILE *out); // although FILE is unusual in C++
};
- comparison to typedef Thing with ThingNew and ThingDelete, etc.
- automatic constructors and destructors
-
students convert an earlier C program demonstrating the
ThingNew/ThingDelete idiom into the equivalent C++
orthodox canonical class form
- default constructor X::X()
- copy constructor X::X(const X&)
- assignment operator X& operator=(const X&)
- destructor X::~X()
access control
- public:
- protected:
- private:
- allowing specific access: friend
object and class relationships
- IS-A
- HAS-A
- USES-A
- CREATES-A
- LIKE-A
inheritance
- simple inheritance
-
students derive new object types with a demonstration program
- virtual functions and abstract base classes
- signatures
- polymorphism
-
students study a window-system-polymorphic example program
further discussion
- templates
- envelope/letter paradigm - representing numbers
- exemplars and the ->make() idiom
suggested reading
Author/s | Title | ISBN | Year |
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 |