Code Critique


Form groups of two or three people. You should start each group activity by introducing yourself to each member of the group. You may also want to choose one person to write down the group's discussion as you go.

This activity is intended to help you to learn to critically read code, understand its purpose, and identify ways to improve it. The following readings --- Code Smells, Open Closed Principle, and Tell Don't Ask --- may help you to identify specific issues in the code. Along the way, you should start to build a sense of what makes one piece of code better than another given a specific set of design goals.

There are three parts to this activity:

A Code Fragment

Look at this handout given previously as an assignment in CompSci 100. Start by reading it and making sure you understand the problem you are being asked to solve. Next, examine the code given as an exemplar for solving the first part of the assignment and discuss its strengths and shortcomings with your group. In your disucssion, attempt to answer the following questions:

A Complete Program

Now, look at this complete student solution to the same problem (in C++ and Java). Start by reading it and making sure you understand the given code. Next, examine the code from the perspective of how it may have been debugged and tested and how it may be extended in the future. Discuss its strengths and shortcomings with your group. In your disucssion, attempt to answer the following questions:

While studying this code, please note any good things about the code, that you might keep in the final version as well as problems with the code.

Refactoring

Refactoring is the practice of updating a program to improve its design and maintainability without changing its current functionality significantly. An example of refactoring is creating a single function or class that replaces two or more sections of similar code because it reduces the amount of redundant code within the program and makes the code easier to debug and test. You should examine the given program and refactor it based on your critique and our discussion in class. You may create (and comment) any new functions or classes you want to help improve the program; however, you should justify each change you make by explaining specifically how it improves the code.

Additionally, you should provide a set of tests that verify your modified program still works as intended. Tests can be in the form of input data files, driver programs, or other classes that verify every line of code written works as intended.


Comments?