Programming techniques (2.2.1) Flashcards
What are the three main programming constructs?
- Sequence
- Selection
- Iteration
What is sequence?
Code is execute line by line from top to bottom
What is selection?
A specific block of code is run if a specific condition is met, using IF statements.
What is iteration?
A block of code is executed a set number of times or while/until a condition is met using FOR, WHILE or REPEAT UNTIL loops.
What is the scope of a variable?
It refers to the section of code where the variable is available.
What are the two main variable scopes?
- Local
- Global
What is a local variable?
A variable that can only be accessed in the block of code in which they are defined.
Local variable ADVS
Ensures subroutines are self-contained i.e. the variable are not affected by code outside of the subroutine
What is a global variable?
Can be accessed throughout the whole program.
Global variable ADVS
Useful for values that need to be used by multiple parts of the program
Global variable DISADVS
- Can be unintentionally overwritten.
- Require more memory than local variables
What is modular programming?
A technique used to split large, complex programs into smaller, self-contained modules.
Modular programming ADVS
- Makes problems easier to understand and approach
- Can divide tasks between a team
- Simplifies testing and maintenance, can deal with each component individually
- Code is reusable
Modular programming DISADVS
- Can cause complexity in simple programs
- May be challenging to keep track of function names and values
What are functions and procedures?
Blocks of codes that perform a specific task
What is the difference between a function and a procedure?
A function returns a value, a procedure doesn’t
What are parameters?
Values that are passed into a function
What are the two methods that can be used to pass parameters?
- By value
- By reference
What is passing by value?
The parameter is effectively treated as a local variable:
-A copy of the variable is copied to the parameter meaning changes made do not effect the value elsewhere.
What is passing by reference?
The address of the parameter is given to the subroutine so the value will be updated at the address giving a permanent change.
What is an IDE?
An Integrated Development Environment is piece of software which provides a set of tools making it easier to write, develop and debug code.
Examples of IDEs
IDLE, Microsoft Visual Studio, Pycharm, Eclipse
Common IDE features
- Stepping
- Variable watch
- Breakpoint
- Source code editor
- Debugging tools
What is stepping in an IDE?
Allows the user to monitor the effect of each line of code by executing one line at a time.
What is variable watch in an IDE?
Used to observe the changes of variable contents in real time
What is breakpoint in an IDE?
Allows to set a point where the program will stop (based on a condition or a specific line), this helps to pinpoint errors.
What features does a source code editor provide in an IDE?
- Autocompletion
- Indentation
- Syntax highlighting
- Bracket completion