unit 2b - programing techniques Flashcards
(40 cards)
what is a scope?
the area of a program where an item (variable, constant, subroutine etc.) is recognised by the program
what is a subroutine?
a selection of code that you can group together under a name and then call later in the program
example:
SUBROUTINE showKeys()
OUTPUT “keyboard controls”
OUTPUT “=============”
ENDSUBROUTINE
showKeys()
note that the subroutine above has no parameters hence the empty brackets
what is data validation?
it ensures that the data entered is the right type
what can validation not ensure?
it cannot ensure that the user has not typed in the wrong value or if there is a spelling mistake but rather if the data is reasonable and conforms to a set of rules
what are the 5 types of validation checks?
range check, type check, length check, presence check, format check
what does a range check do?
checks whether a number or date is within a sensible/allowed range
what does a type check do?
checks if the data is the right type eg. string or integer
what does a length check do?
checks if the data entered is of the right lengtheg. between a certain number of characters
what does a presence check do?
checks if data has been entered into a field or not ie. in case the field has been left blank
what does a format do?
checks if the data is the correct format eg. if was a postcode or email address
what is verification?
it is used to double check that the data has been typed in correctly
what is double-entry verification?
example: if a user is making a new password, they may be asked to enter it twice and if the two passwords don’t match, they’ll be asked to enter it again
what is authentication used for?
used to make sure a person is who they claim to be - checks this by identifying a valid username and password
how can programs be made easier to understand and maintain?
- comments to show who wrote the program and when
- comments to explain what the harder parts of code do
- comments to explain the functionality of each subroutine (function or procedure)
- meaningful variable names
- a modular structure
what are trace tables used for?
used to determine the outputs from a program as it runs. enables a programmer to find errors in their programs
how do your create a trace table?
- make a column of each variable used in the order in which they appear
- record the value of each variable as it changes
why is a trace table useful?
- determining the purpose of an algorithm
- finding the output of an algorithm
- finding errors in an algorithm
what are logical errors?
any error that isn’t a syntax error so the program will run/compile but not as intended by the programmer
what are syntax errors?
where the code written doesn’t conform to the rules of the language - the program can’t be run (and will return an error) if there are syntax errors
what is testing and why is it important?
it is important that the programs are fully to find logical errors
a test plan tests for normal data, boundary data and erroneous data
what is normal data?
program: number between 1 and 100
normal data would be 5 (checks a single-digit) and 14 (checks two digits)
what is boundary data?
program: number between 1 and 100
so boundary data would be the values either side of the boundary.
- 1 (checks the lowest valid data)
- 100 (checks highest valid data)
- 0 (checks invalid data at the boundary)
- 101 (checks invalid data at the boundary)
what is erroneous data?
program: number between 1 and 100
erroneous data would something completely out of the range like -5 (checks a negative number) or 1012 (checks a large number) or “#$%” (checks that the data is of the wrong type) is rejected
what are two techniques to finding logic errors?
- trace table - traces through a program to scan for errors
- inserting output statements at various points in the program to find the values of variables