update functions page

This commit is contained in:
2026-03-02 14:32:04 -06:00
parent 332683b007
commit 3a42126ede
2 changed files with 26 additions and 0 deletions

View File

@@ -8,3 +8,29 @@ tags = 'cpp'
chapterno = 3
+++
## Documentation practice
It is a good idea to include comments along with the functions you create and should only be put within the function prototype. They should include:
- A brief description of its purpose:
- Precondition:
- The conditions that are required in order for the function to work properly.
- Postcondition:
- Only include if the final result of your function is difficult to understand by reading the code.
Make sure when creating comments, do not state the obvious. They clutter your code and make it more difficult to read your code. Only include comments to things that are complex or difficult to understand.
Example:
```c++
// Description: Returns the square of a number.
// Pre: Size of x must be less than size of int when squared.
int square(const int x);
int square(int x) {
return x * x;
}
```
Function abstraction is the ability to make a function easy to use without understanding exactly how the function works line by line. This makes it easy for other people to use your code faster. It is a good practice to make your code easy to use for other people.