Bins Revisited

Luke Forster

Code Fragement

How clearly written is the code?
It is very clearly written and easy to understand.
What, if any, comments might be helpful within the Code?
The code is self-documenting, as we talked about in class. The only comment that I could possible think about adding is a comment on the disk class i.e. //class you are to design which has freespace and add member functions
Does it satisfy its role as a tutorial?
Yes, it does satisfy its role as a tutorial. First of it solves almost half the assignment for the student and gives then a good structure for the second part. It also clearly guides them in the best way to solve this problem.
What, if any, suggestions does this code make about the how remaining parts of the assignment will be written?
Well I believe that this code gives various suggestions. First of all, the student coder will probably just take the first part, copy and past it and then modify it so that it works for the second part. It also suggests how disk class should be designed. This code suggest that disk class have freespace and add member fuctions but it also tells the coder that he/she needs to overload the < and == operators
How would you test this code for bugs?
First of I would test run a few numbers through the code. What I mean by that is I would think up three or four numbers and then use pen and paper to see if the code fragment works. If there are errors I would try and fix them on paper, if there are none or I fixed them then I would type into eclipse and run it on a file with alot of numbers. If I have a problem then, I would use the step-by-step debugger to find the bug. Finally, I would think up some tricky test cases, aka all the files are the same size or something like that, and see if my program still worked on those cases.

Complete Program

Does it satisfy the requirements of the assignment?
Yes, this program should execute both heuristics correctly.
What, if any, comments might be helpful within the code?
First, I like to put my name, the date and basic information on what a class does at the top of my .h files. Also, in the client file, he has no comments. I would like to see comments at the top of each method i.e. //reads in numbers from a file into a vector Also a comment on which is worst-fit in-order and worst-fit in-decreasing-order would be nice.
How easy do you imagine this code was to write, test, and debug?
I imagine that it was not to hard to write given the tutorial did half the woke and gave the programmer a easy path to follow. As for testing, I think it would be pretty easy, especially because in 100 the give you test cases, and all you have to do is take those test cases make a file and run the program on the file. However, I think debugging would have been a headache. Because if there is an error in one of the heuristics then there will be an error in the other, and you have to remember to make changes to both loops. Also, debugging a class can be hard because the error messages might as well be written in Russian.
How would you test this code for bugs?
Well since there are so many areas for possible infestation I would do a piece by piece debugging. First of I would do the most basic of member functions in the class: add and freespace. Then I would make a simple temporary client to test these fuctions. From there I would fix any problems that arise and add new member functions, print and aggain use a temprary client. Finally, I would add the overloaded operators and test them. Once I knew for certain the class does not have any bugs, I would start of the client. First, I would use the code they gave me and make sure there were no bugs. I would suspect there are none, maybe just a few typos, because what teacher would give new programmers buggy code. Then I would figure out how I would need to modify the code to complete the second heuristic. Then I would test that for any bugs, by running a few simple numbers through them, and then do a lot more numbers, and continue adding numbers until I felt certain that the program was working. Finally, I would do cosmetic touch ups, like comments, change everything from one long int main into functions. Finally, I would test it one last time and if it still worked, I am done.
What, if any, additional functions may be helpful?
Well I think you should add a one new functions The function I would add would be the heuristic function, which would take a priority queue of disks, and a vector. This function would basically execute the heuristic. The function would consist of the for loop, for(unsigned int k=0;kWhat, if any, classes may be helpful?
I think a class which implements the heuristic would be a useful addition, so that it would be easier to add new heuristics.
Good and Bad code
I think the class is programmed very well, and I think his modifications on the heuristic made it less repetitive and more streamlined. However, I still think he can cut down one his code and make it less repetitive.

Refactoring

Justification

First let me explain my goals and assumptions. I assumed that the main focus of this assignment, other than figuring out how to use priority queues and make classes, was to implement the best heuristic. I also assumed that the disk class was more representitive of the real world, and its main focus was to show how effective one heuristic was verses another. In other words, heuristic A used ten discs while heuristc B used 9. Taking all this into account the focus of my refactoring was to cut down on repetitive code and at the same time make it fairly easy to add new heuristics. My first change, was to create two new functions, doheuristic and printpq (Both still in bins.cpp). The purpose of creating these new functions was to cut down on reptitive code because both worst-fit in-order and worst-fit in-decreasing-order used the same code. However, I wasn't satisfied, because if I wanted to add a new heuristic it could take alot of modifications, so in order to make it easier to include new heuristics, I made a heuristic superclass, which has two pure virtual functions, DoHeuristic and PrintHeuristic. so in the Worstfit base class DoHeuristic executes the heuristic, so in this case it uses a priority queue of disks and adds a file to the disk if it has enough space. PrintHeuristic, prints the priority queue. However, if you would like to add a new heuristic all you have to do is create a new base class which defines DoHeuristic and PrintHeuristic, and then add a few lines to bins.cpp and your golden. So that explains my additions, next let me explain why I kept the code I kept. This student programmer did a good job of writing some good code. For example, The code to execute the heuristic was very good and I took that and incorporated it into my Worstfit class. Another example is the disk class. Since I only though that disk was representitve, it seemed good enough to be used now and later without any changes. As for reading in a file of ints and storing it in a vector, I think that ints are two representitve and that any major demands for change on bins will not be to add strings. However, this is one of the weaknesses of my added classes, because if you change what you are using as data from ints to anything else, you break all my classes and the disk class. So, in conclusion, I created a new class Heuristic so that implementing new heuristics would be easier, but I left some of the code because it was good enough to do its job.