Development Strategy for C Programs

It is important that you develop your code development, debugging and testing skills. We can provide guidance during office hours, but it is important that you have a strategy that helps you develop, test and debug your code on your own and with the minimal assistance possible.

Below we provide information about a strategy you should follow while implementing code. If you are taking cmsc216, and you are looking for help during office hours, we expect you to follow a similar strategy, otherwise we will not be able to help you :(. The strategy can be summarized as follows:

Strategy Summary

  1. Add code incrementally (e.g., code fragment or a function) → If you write a lot of code you are making the debugging task harder. The code you write should have good indentation and good variable names from the start. This will make the debugging task easier and help TAs provide assistance.
  2. Do not ignore compilation warnings.
  3. Create your own tests → Make sure the code you just added is correct by creating your own tests. Usually provided tests (e.g., public tests) test several aspects of your code simultaneously. You need a test that is specific to the code you just wrote. Also, submit your code often to the submit server to verify your code works as expected in the server.
  4. Rely on tools like Valgrind, gdb, splint → Use tools like Valgrind to identify common errors like reading unitialized data, performing invalid read / write operations, or dynamic memory problems. You need to run Valgrind after you add some code and not once you have implemented all your code. Tools like splint can help as well. If you code is generating a seg fault / core dump, use Valgrind or gdb (where option) to identify the problem. If this does not work, step through the code using the simple test you developed.
  5. Backup your code → Once your code is working, create a backup of the code before you continue working. Backups help as sometimes you would like to go back to code you had (or in case you delete your code by mistake).
  6. Take breaks → Many errors can be found easily if you take a break and focus on something else.
  7. Go back to step one.

Additional Information

Web Accessibility