CPS 108 C++ Code Critique: du
Fall 1998
You are to understand and ultimately critique the following program
which attempts to replicate some of the functionality of the Unix command
du
, which stands for "disk usage". It is less flexible than the corresponding
Unix command, but produces output that may be seen as "more user-friendly".
See the Unix man page on du for more information.
Analysis
You should analyze the code given and write a description no longer than
one paragraph that describes its use and functionality. Your description
should be suitable for use in a user's manual or manual page; however,
it should be in your own words --- i.e., you cannot just copy the current
Unix man page.
Additionally, you should answer the following questions in as much detail
as you can.
-
Does the function dirCount count directories? What would
be a better name?
-
Does the function dirSize count the size of the directory?
If so, what is the assumed size?
-
Why is nameFromPath called, it is not commented on so why use
it? Also, what is DIR_SEPARATOR and where is it defined?
-
How many times is the directory structure traversed? Note, think
about the leaf files separately from the root directory.
-
What will happen if you run this program with a file name instead of a
directory?
Critique
You should critique the code and design of the program. The program has
some good qualities, but the design and code also have some problems. You
should write a one paragraph to one page critique of the code and design.
Your critique should address at least the following issues:
-
Describe at least five things about the program that are "hard-coded",
or unchangeable by the user.
-
Describe, in enough detail that someone else could write the code, how
the current code could be modified to allow the user to vary three of the
things noted above.
-
The code given is mostly procedural, i.e., it does not define any new classes.
Explain why (or why not) it would be worth the effort to define at least
one class. What would the interface for such a class look like?
-
How could you modify the code to be more efficient? In particular,
can you describe an O(N) algorithm, where N is the total
number of files in the given directory.
-
Can you think of any additional classes you might want to define?
Note, think about this in conjunction with the previous question.
-
It is stated that the output is more "user-friendly". Is this true?
Note at least one good thing and one bad thing about the format of the
output. How could you make it configurable?
In addition to the questions above, your critique should include some general
comments:
-
Problems with the code, things that have easy fixes but that show flaws
in use of C++ or coding in general.
-
Problems with the design. There may be immediately apparent problems with
the design of the program/class, but you may find it necessary to think
of how the program might be used in order to make pronouncements on design
flaws. For example, often a program is used in unanticipated ways. A good
design will facilitate changing/extending the code or using it in new ways.
-
You should find at least three good things in the code and note those too.
Comments?