update functions page
This commit is contained in:
Binary file not shown.
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user