1/40
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What do subroutines allow?
Allows code that you intend to use multiple times to be grouped together under 1 name
Examplse of subroutines
functions and procedures
What does a function do that procedures don't?
Functions will return a value after processing has taken place
pseudocode of a subroutine
SUBROUTINE subroutineName(parameters)... ENDSUBROUTINE
why use subroutines?
Break up large programs into self-contained units
Each subroutine can be tested separately to make sure it works correctly
Cuts down development time: many programmers can work on a large program at the same time
Subroutines can be re-used in other programs
Subroutines can be stored in a subroutine library and used in different programs
Program maintenance is easier: if requirements change then just the affected subroutines need to be modified
what is the scope of a variable/constant/procedure/function?
parts of the program in which it is recognised and can be used/the specific region of a program where a variable, function, or object is visible, accessible, and can be referenced.
local variable definition
Local variable = variable created in a subroutine
local variable parameters?
Only exist while subroutine is executing, Only accessible withing the subroutine
global variable definition?
variable created outside a subroutine
'parameters' of a global variable?
accessible anywhere in the program
pseudocode of a global variable
global variablename
advantages of using local variables
Keeps a subroutine self-contained --> can be used in any program without variable names conflicting with those used in the calling program
Easier to debug program: value of that variable can only be read or changed within one subroutine
Memory efficiency: once a subroutine has finished running, the memory used for all local variables is removed
Disadvantages of using local variables
Limited scope
Potential for data redundancy (needing repeated passing)
Short lifetimes: memory freed when function ends - problematic for persistence
Advantages of Using Global Variables
Large scope: can be accessed from any function
Reduced Passing: no need to pass the same variables as parameters between different subroutines
Only needs to be declared once
Disadvantages of Using Global Variables
Harder to debug: any function can change a global variables - finding where a variables was incorrectly updated is difficult
Too many global variables can clutter namespace --> name clashes where local variable might mistakenly override a global one
Memory usage: stay in memory for entire duration of the program
What way should subroutines be written and why?
Should be written in a modular way so that they can be reused multiple times in the program or by other programs
What should well documented modules/subroutines show?
The parameters that the subroutines take, what they are used for and what data types are needed
Purpose of the subroutine
Return value and its data type
Advantages to structure programming
Modularised approach - breaks down programs into manageable chunks of code
Helps to decompose larger problems
Programmers only need to use the interfaces of subroutines = parameters and return values
Don't need to worry about internal workings of each subroutine
Fewer bugs + easier to maintain
What do data validation routines ensure?
ensure that data entered is of the right type (i.e. data type)
what can't validation make sure of?
Validation can't make sure that the user hasn't entered a wrong value/make a spelling mistake in a name
what can validation only ensure?
Can only ensure that data is reasonable and conforms to a set of rules
what is a range check?
checking data is between 2 values
what is a type check?
Data is of the right type, e.g. integer/letter/text
what is a length check?
Text entered isn't too long/short
what is a presence check?
Checks that data has been entered - field hasn't been left blank
what is a format check?
Checks that the format of, e.g., a postcode/email address is correct
what is an authentication routine
a routine to check that a user enters a valid username and password
validation definition
checking that data is reasonable
verification definition
double checking data from an alternative source or re-typing it
Ways to make Programs Easier to Understand
Comments at the top to show who wrote the program and when they wrote it
Comments to explain what harder parts of the code do
Each subroutine (function or procedure) should have comments to explain their functionality
Use meaningful variable names
Use subroutines/ a modular structure
Meaningful identifiers
What are trace tables used for?
Used to determine the outputs from a program as it runs
Enable a programmer to find errors in their programs
Can be used to find the purpose of a flowchart/pseudocode
what are syntax errors?
an error where the code written doesn't conform to the rules of the language
wat are logical errors? + description if code run
remaining error is a logical error, Program will run, but won't work as programmer intended
what is a test plan?
a structured document created during the design phase to ensure software meets requirements
what is used in normal data testing?
Uses typical/expected/valid inputs
What does normal data testing check?
Checks if a program works correctly under everyday conditions
what is used in boundary data testing?
Checks edges of valid input ranges and values just outside them (by 1)
what does boundary data testing ensure?
Ensures a program correctly accepts valid limits and rejects invalid ones, preventing errors/making software robust
what is used in erroneous data testing?
Uses incorrect/unexpected inputs (e.g. symbols, strings, negative numbers)
what does erroneous data testing ensure?
Ensures it doesn't crash + provides useful error messages, rather than processing bad data
How to find logical errors
Trace table: useful for tracing through a program in order to find a logic error
Value of each variable recorded as it changes
OUTPUT statements at various points in the program to check the values of variables