# Class 22: Program Documentation

Back to Function Basics. On to Asymptotic Analysis.

Held: Tuesday, 25 February 2003

Summary: Today we consider ways to use assertions to document and describe programs.

Related Pages:

Due

• Gries 6.

Notes:

• This outline was created a day late. Sorry.

Overview:

• Using Assertions.
• Notation.

## Using Assertions

• As you know, we're developing all of this theory about assertions so that we can use them in programs.
• There are at least two key ways we'll use assertions.
• Most frequently, we'll use assertions to indicate what we plan for our code to do.
• In this case, we write preconditions and postconditions for our procedures (or statements).
• We can then use some careful reasoning to show that the code plus the preconditions lead to the postconditions.
• Although we haven't done the proof part in other courses, we've discussed care in writing preconditions and postconditions.
• Sometimes, we'll use assertions to formally define the statements of our language.

## Notation

• Just as in the case of informal assertions, we need to be careful that someone doesn't try to meet our postconditions by doing something other than we expect.
• For example, if the postcondition is simply `{ x=y }`, one can reach the postcondition by simply setting both x and y to 0.
• To indicate constant values, we use capital letters.

## Assignment

• We'll consider (as a group) how we might use assertions to indicate the meaning of assignment operations.

## Sorting

• There are two primary ways to think about sorting:
• `sort(source,destination)` puts the result of sorting into destination (and doesn't change source).
• ```sort!(source) sorts in place. ```
``` ```
• ``` We'll consider (as a group) how we might use assertions to indicate the desired results of a sorting procedure. ```
• ``` Along the way, we'll need to consider the formal specification of permute(x,y). ```
```   History Tuesday, 7 January 2003 [Samuel A. Rebelsky] Created generic version to set up course. Wednesday, 26 February 2003 [Samuel A. Rebelsky] Filled in the details (a day late ...).   Back to Function Basics. On to Asymptotic Analysis. Primary: [Front Door] [Current] [Glance] - [Blurb] [Disabilities] [Honesty] [Instructions] [Links] [Search] [Syllabus] Groupings: [EBoards] [Examples] [Exams] [Handouts] [Homework] [Labs] [Outlines] [Readings] [Reference] ECA: [About] [Grades] [Quizzes] [Submit Work] [Change Password] [Reset Password] Misc: [Walker/Fall 2001] [SamR] Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes. This document was generated by Siteweaver on Fri May 2 14:20:35 2003. The source to the document was last modified on Wed Feb 26 13:35:45 2003. This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS195/2003S/Outlines/outline.22.html. You may wish to validate this document's HTML ; ; Check with Bobby Samuel A. Rebelsky, rebelsky@grinnell.edu ```