CS 204: Software Design

Takehome Exam

Due on paper by 5:00PM Saturday, March 15, 2008.

This is an exam. You may use any book, your notes, stuff you find on the Internet, etc. (all with proper citation), but you may not discuss the details of exam with any person other than Jeff Ondich. This prohibition includes, of course, discussions held electronically.

  1. (8 points) Assertions and Exceptions

    • Suppose you are writing a Python program, and you come to some code that opens a file whose name is provided by the user. Would it be appropriate to put this code in a try block? If so, what should go in the corresponding except block?
    • Same situation as above. Would it be appropriate to use an assertion (e.g. "assert myfile") to protect against the failure to open the file? Why or why not?
    • Give one good example of a place where you should use an assertion. (Cite your source if the example doesn't come straight out of your head.)
    • Suppose you are writing a Java string-manipulation method that takes one String as a parameter. It is possible for your method to be called with a null string reference as its parameter. You can protect against this possibility using assertions, exceptions, defensive programming (e.g. do nothing if the parameter is null), or some combination of these techniques. Which will you choose, and why?
  2. (8 points) UML

    Imagine you are designing genealogy software to help people keep track of their family trees. You will certainly want to have classes to help you keep track of individual people, their relationships, immediate families, documents associated with people (e.g. digital images of census death certificates), etc.

    Your job for this problem is to draw a UML class diagram for some portion of your fictional genealogy program. The point of this exercise is to get you comfortable with some of the basics of UML class diagrams--not to create a full-fledged design for a genealogy program (which would be a very complex task). With that in mind, your class diagram should include at least five classes, at least one inheritance association, and at least one composition association (with multiplicities indicated as appropriate on the ends of the composition arrow). It's important that your inheritance and composition associations make sense in the genealogy software context, but it is not necessary for you to make your diagram complete.

    You may use either drawing software or a pen and paper to create your diagram.

    If you use a particular reference for learning about UML class diagrams, please give me the book title or URL of your reference(s). Note that a Google search on "uml class diagrams" gives you some good choices.

  3. (8 points) Hungarian Notation

    Six months after graduating in 1998, one of our CS majors who went off to become a programmer (and whose stock options have made him quite wealthy) wrote to me raving about a paper that I needed to read and then start teaching to my students. The paper, Hungarian Notation, by Charles Simonyi of Microsoft, describes Simonyi's naming system for identifiers (variables and constants, in particular).

    Read Simonyi's paper, and then answer the following questions.

    • Why is the system called Hungarian?
    • Summarize the benefits of the Hungarian naming system.
    • Summarize the disadvantages of the Hungarian naming system.
    • Using the Hungarian notation style, write a static Java method that takes a string and an integer as parameters, and returns a string consisting of the last N characters of the original string, where N is the integer passed in as a parameter. (If the original string has no more than N characters, return the original string. If N < 0, return the empty string.) The point of this exercise is to use the Hungarian notation (changing, for example, the name of N to something more in line with Simonyi's approach). So if you can make the function body essentially trivial by using Java String methods, go right ahead.
    • Do you think we should encourage our students to use the Hungarian system? Why or why not?
  4. (8 points) Excise

    Read Chapter 11 "Eliminating Excise" from About Face 3. In light of the contents of this chapter, write a list of your top five recommendations for improving the user interface of thehub.carleton.edu. For each recommendation, refer to appropriate parts of Chapter 11. Note, by the way, that the goal here is well-justified constructive criticism. Though I am not a fan of the overall user interface at thehub, I am a huge fan of the functionality it provides to us all.

  5. (8 points) Undo

    Read Chapter 16 "Understanding Undo" from About Face 3. In light of this reading, provide a short (no more than one page) discussion of the undo capabilities in any painting program (e.g. MS Paint, which comes standard on Windows). Include a brief description of the program's undo structure, and then discuss the the strengths and weaknesses of the system, referring as appropriate to Chapter 16.