Please enable JavaScript.
Coggle requires JavaScript to display documents.
A-Level Computer Science - In Class Paper 1 (IDEs (Allow programmers to…
A-Level Computer Science - In Class Paper 1
Variables
Global Variables
Variables which can be used anywhere in a program, even i subroutines
When a variable is declared, they are global by default
Why are they often avoided
Needs to be in memory all of the time
Can not be used for the creation of libraries
Cannot be used to write self-contained code
Harder to find bugs due to the large scope of a global variable, spanning the whole program
Local Variable
Can be used and executed within a a subroutine
Can only exist during the execution of the subroutine that it is in
Cannot be accessed outside of a subroutine
They don't affect any variables outside of the subroutine if they are changed or if they have the same name as a variable outside of the routine
Ensures each subroutine is self-contained
Parameter passing
Parameter
Data that you pass through a function or a procedure
Passing it by referencing it (REF)
Allow you to pass parameters by reference to the original one
Passing a pointer to the function that points to the original parameter
You put the variable into the function, and it changes the original value of the variable
Passing it by value (VAL)
Involves taking a copy of the parameter first, then passing the copy through the function
Does not affect original variable value or change it - takes the value instead like a copy
Functions and Procedures
Functions
Is able to return a single value to the main program
(Value is passed back to the main program using variable which the same name as the function)
Both subroutines of code
Can both accept parameters
Procedures
Doesn't return values at all
Can both do calculation on code
Recursion
A subroutine which is able to call itself
Must have a
base case
- a stopping condition that will stop the routine from being called when met
The stopping condition
must be met after a finite amount of times
For a function to be recursive it
has to be able to call itself
Identified by seeing the function name called again but with different parameters. Also look for a base case - while, for AS LONG AS IT USES THE FUNCTION
Programming language constructs
Iteration
:
Iteration is where there is a section of code within a program which is able to repeat and loop itself over and over
While, end while
Repeat, until
Selection
Used to select which statement will be executed next in a piece of code, depending on whether certain conditions were met
Relational operators
'>' Greater than
'<' Less than
'>=' Greater than or equal to
'<=' Less than or equal to
'==' Equal to
'!=' Not equal to
If, elif, else
Sequence
When statements of code are executed one after another
Used in procedural programming
IDEs
Allow programmers to write and edit code
Allow for code to be compiled and run
Debugging tools
Testing tools
Step through
- Allows the programmer to see what is happening in the code, line by line to see what the code is doing exactly at each line
Watch
Can be set to a variable to allow the programmer to see when the variable. Will output every time the variable changes
Breakpoint
Puts a break point at a certain part of the code. Allows the programmer to see if the code will reach that line and what happened in the code before that line is reached
Modular Coding (Subroutines)
Advantages
Small and understandable unit of code
Can be tested independently from the rest of the code
Unit of code can be reused in other programs or in different parts of the same program
Modular approach allows for a team of programmers to split up and work on a specific set of subroutines, thus allowing for the whole program to be created faster - it can be broken up across a team of programmers
Subroutines make it easier to monitor and control the program - important for large programming projects