BitSet notes P.J. Drongowski 15 September 2004 (Updated 28 January 2005) BitSet interface issues * What is the abstraction that BitSet embodies? (Finite set of positive integers from 0 to 127) * What does the BitSet class attempt to hide? * Does the BitSet interface do a good job of hiding the implementation? * How can we make the BitSet interface better? * Does use of unsigned int pose any portability problems? Yes, the implementation is dependent upon the platform/compiler implementation of an unsigned int (i.e., number of bits may vary.) * Could we have selectively exposed the elements array to do "white box" testing? Tour of BitSet * How is a C++ module/class organized? + Declaration of class interface is in an include file (.h) - What is an include file? - What is the C++ preprocessor? + Definitions of method functions are contained in source file (.cpp) * Class interface (the include file) + Inclusion - Is included into the defining source module and any module using the class - Declaration of the interface may be included multiple times -- bad! - Must surround declaration with #ifndef - Explain how #ifndef works + Class declaration - Data members and method functions are private by default - Good coding style to make public and private explicit + Two kinds of C++ comments - // comments are good for single line comments - /* ... */ comments are good for multi-line comments - /* ... */ comment can be used to selectively eliminate chunk of code + Note use of three different constructor methods - Compiler will choose constructor based upon function signature - Might want to experiment and see when constructor gets invoked + Mutators and accessor methods (set and get) - "Get" functions return values; isolate internal data from external use - "Set" functions allow using module to change state in a controller way + One data member - The current elements (members) belonging to the set + Class constant - "static const" - "static" means "shared by all objects belonging to the class" - "const" means "the value of this symbol will not change" - "const" is the prefered way to define a constant; it allows type checking by the compiler * Class definition + Includes the standard stream I/O library "iostream" + Uses the standard namespace "std" + Includes the class interface declaration + Defines two tables containing mask values - First table contains masks to select individual set elements - Second table contains masks to clear unused bits + Constructor methods - Constructor methods should check validity of their arguments - Concept of a class invariant -- a property that should hold across all objects in a class at completion of any method + Explain use of the unionOf method - Tried to make use of this method symmetrical - The & declares a formal parameter to be "by reference" - "By reference" avoids copying when passing the actual parameters (C++ default parameter passing is "by value") * The function main is needed to "drive" the program -- it is where execution starts + The arguments to main pass in command line options + Main declares and defines four sets (note inconsistent use of SIZE!) + Explain insertion operator (<<), cout and endl + Discuss use of FAIL and PASS in program output (can be used to automatically detect failure or success by postprocessing test output) * Logistics + Where to find source files: /g/15/class/project1 + Which system to use: comp15.eecs.tufts.edu + Which g++ compiler to use (v2.93) + Use ssh to connect to comp15.eecs.tufts.edu Sizeof and portability * What is a "portable" program? What is "portability?" * It's sometimes necessary to write a program that will run on different platforms (instruction set X operating system X compiler) * Making a program portable opens the market for that program to a wider range of customers -- very good for business * "Independent Software Vendor" or "ISV" * Size of integer datatypes varies from platform to platform, sometimes from compiler to compiler on a given platform * The C/C++ sizeof operator returns the size (in bytes) of a data structure or type in bytes; Try: unsigned long long int big_dude ; cout << sizeof(big_dude) << endl ; * Code using sizeof is sometimes error prone + Let the compiler do type checking instead + Define an include file ("port.h") that defines int types of specific bit lengths + Use predefined standard types - Sometimes a treasure hunt to find the right include file! * /usr/include/sys/types.h * /usr/include/machine/types.h - int8_t, u_int8_t, int16_t, u_int16_t, int32_t, u_int32_t, int64_t, u_int64_t, Forecasting, estimation and measurement * What is the first question your manager will ask after giving you an assignment? "When can I have it?" * Delivery schedule may be driven by external business factors, like "We need a demo for the next trade show in six weeks." * Managers expect to get a development plan that shows the tasks, milestones and deliverables. - It's hard to define a schedule when there are so many unknowns - Experienced engineers have difficulty estimating task duration - One approach is to use/adjust time needed to implement a similar solution * Software development should be predictable and repeatable * Here's something you can begin to do now + For each assignment, predict how much time you will spend in design, coding, debugging, testing and documentation + Keep a diary that tracks the actual amount of time spent doing these activities + Compare the estimate with the actual -- how did you do?