Exercises and Discussion Topics

  1. Experiment to find-out how your C, C++, and Java compilers deal with uninitialized variables. Outline your results and propose an inspection procedure for locating uninitialized variables.
  2. Look in the course's source code repository for programs that do not verify the result of library calls. Propose practical fixes.
  3. Examine the visibility of functions and variables in programs in your environment. Can it be improved (made more conservative)?
  4. Discover how the editor you are using can identify matching braces and parentheses. If it can not, consider to start using another editor.
  5. Provide five examples from the course's source code collection where the code structure can be improved to make it more readable.
  6. You can find tens of intentionally unreadable C programs at the International Obfuscated C Code Contest web site. Most of them use several layers of obfuscation to hide their algorithms. See how gradual code changes can help you untangle their code. If you are not familiar with the C preprocessor try to avoid programs with a large number of #define lines.
  7. The Perl language mandates the use of braces for all its control structures. Comment on how this affects the readability of Perl programs.
  8. The code body of switch statements in the course's source code collection is formatted differently from the other statements. Express the formatting rule used, and explain its rationale.
  9. The for statement in the C language family is very flexible. Examine the source code provided to create a list of ten different uses.
  10. Locate ten occurrences of break and continue in the source code provided with the course. For each case indicate the point where execution will transfer after the corresponding statement is executed, and explain why the statement is used. Do not try to understand in full the logic of the code; simply provide an explanation based on the statement's use pattern.
  11. Find, simplify, and reason about five non-trivial boolean expressions in the source-code base. Do not spend time on understanding what the expression elements mean, concentrate on the conditions that will make the expression become true or false. Where possible, identify and utilize the properties of short-circuit evaluation.
  12. Study Section 2.11 from the book. Provide a proof about the correctness of a sort algorithm, found in the course's soruce repository.