Object-Oriented Design Frequently Asked Questions


Python

How does one check whether an object c is of "type" C ?

  1. If the object c is a literal and the type C a builtin type (such as an int) which cannot be instantiated, then the test
        c == int(c)
    can for example be used (as in the Roman Numeral example).

    If the object is not a literal type, one can explicitly query the object's type. This is done by loading the module types and using the type() operator.

     
        import types
        type(1) == types.IntType
        
    To check what the pre-defined basic types are:
        dir(types) 
  2. If the object c is however an instance of a class, and we want to check if c is an instance of class C, we can use the test
        isinstance(c, C)
    This will evaluate to True (1) if c is an instance of class C or any of C's sub-classes.

    In recent versions of Python, it is possible to test for basic types with isinstance as in isinstance(1,int), isinstance(1.2,float) and isinstance([1,2],list).

How do I generate nice HTML from Python source code ?

  1. Colorized pretty-printing for file code.py can be done with
    enscript -Whtml -Epython --color code.py -o code.html
  2. An API document for file code.py can be generated with
    pydoc -w code

Assignments

What are the algorithms needed to evaluate() a spreadsheet ?

The topological sort and strong component algorithms are given here in pseudo-code. More details (on for example algorithm complexity) are found in the literature.

MUST we work in teams of 2 ?

You must work in a team of exactly two people. Previous experience has shown that after the initial transient chaos of finding a partner, this works really well. Try to find a team partner after class. Remember that "pair programming" requires you to actually work together (same place, same time). You may form different teams for different assignments.

Typos in assignment 1

There are several typos on the assignment 1 design drawing.