Bins: Code Critique
This project is intended to help you to learn to critically read code, understand its purpose, and identify ways to improve its design. Along the way, you should start to build a sense of reader's expectations about code and what makes one piece of code better than another given a specific set of design goals.
Part 1: Design Review
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 describe its strengths and shortcomings. Include your answers the following questions as part of your review document:
- What specific pieces of code help versus obscure your understanding of the algorithm?
- What, if any, comments might be helpful within the code?
- Does it satisfy its role as a tutorial?
- What, if any, suggestions does this code make about the remaining parts of the assignment will be written?
- Based on your responses above, rate how clearly the code is written.
Now, look at this complete Java solution to the same problem that extends the given example. Examine the code from the perspective of how it may be further extended in the future to compare the performance of a wider variety of fitting algorithms. Include your answers the following questions as part of your review document:
- Does it satisfy the requirements of the assignment?
- What, if any, comments might be helpful within the code?
- What, if any, additional functions may be helpful?
- What, if any, classes may be helpful?
While studying this code, also note any good things about the code, that you might keep in the final version as well as problems with the code.
Your grade will be determined primarily by how well you justify your statements about the code rather than simply how many things you say. In other words, if you feel strongly that the code is perfect as is and there are no no changes to make, you can still get an excellent grade if you completely justify why the code succeeds in the context of your design objectives. On the other hand, you can also decide the code should be scrapped entirely but, again, you must clearly justify your decisions and why the given code has no redeeming qualities. Justifications that refer specifically to principles given in the resources below will be given higher credit than those that use terms like "clearly/obviously", "good/sucks", or "like/hate".
Refactoring (in class)
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. In class we will refactor the given code based on your reviews. For each change we make, we will spend time justifying specifically how it improves the code.
For extra credit, explain how to change our refactored program to print the algorithm(s) that produces the smallest sets of disks required to fit all of the files.
Part 2 : Test Plan
To prepare for the next class, create a Test Plan that consists of values you plan to use to test this project, i.e., input values and their expected output values. Each set of input values in your plan should have an associated explanation of what code it is testing and why. The goal is to build a suite of tests that can be run automatically rather than requiring you to re-create each test by hand (and under time pressure).
Note, in the given code, there is one known bug, one potential bug not exploited by the given data files, and one kind of numeric input value that the program arguably does not handle properly. Describe these problems and how you discovered them.
Resources
The following readings provide principles for improving the design of the code.
- OO in One Sentence by A. Hunt and D. Thomas
- Open Closed Principle by R. Martin
- Code Smells by K. Beck and M. Fowler