|
In VCE Software Development, the term 'internal documentation':
- refers to meaningful comments and syntax of the code and modules (e.g. functions)
- justifies the use of a particular processing feature.
Commenting your code
Please comment all code that you submit. Here are some guidelines:
- Put a comment block at the top of all files.
- Put a comment block before functions.
- Put a single line or multi-line comment above each significant block of code to describe what it is doing (e.g. what a loop or conditional statement is doing, what data a form is collecting).
- Only comment parts of your code that are important, interesting or not obvious.
- Use correct grammar and spelling in comments.
There are two types of commenting syntax in Python:
- The first are single line comments, which are prefixed with
#.
- While the second are multi-line comments, which start and end with
""" and """.
Use # for single line comments. This
is useful for writing a short comment or for commenting out one line of code.
Single line comments
Put one space after the hash symbol to make it easier to read.
# This is a single line comment
Commenting out a line of code:
# print('This in line 03')
Multi-line comments
Use three double quote symbols, " " ", at the start and end to create multi-line comments. This is useful for writing longer comments and for commenting out whole blocks of code. Format your comments nicely to make them more readable.
""" Nicely formatted comments are easier for everyone to read and to make sense of """
Commenting out a block of code:
""" def hello_message(message): return 'Hello ' + message """
As a minimum, all .py files should have a comment block at the top, similar to the following:
""" State the purpose of the file here, e.g. SoftDev Unit 3 – Week 2 Task 1b
Put a description here, e.g. Uses print to display hello world on screen
@author: <Author's Name> @copyright: <Company Name> <Year> """
Functions should have a comment block at the top, similar to the following:
""" Function: Returns the purchase price Description: Calculates purchase price by adding GST and adding sales margin Author: Bob Smith Input: base_price (float) Output: purchase_price (float) - Base price plus GST """ def calculate_purchase_price(base_price): purchase_price = base_price + (base_price * 0.1) return purchase_price
Variables can be commented like this:
age = 0 # User’s current age in years
|