2.2.1 programming techniques Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

name 3 programming constructs

A
  • sequence
    -selection
    -iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

sequence

A

Code is executed line-by-line, from top to bottom

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

selection/branching

A

A certain block of code is run if a specific condition is met, using IF
statements. This is also known as ‘selection’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Iteration

A

A block of code is executed a certain number of times or while a condition is met. Iteration uses FOR, WHILE or REPEAT UNTIL loops
Iteration can be either:
- Count-controlled
Iteration is repeated a given number of times.
for
-Condition-controlled
Iteration continues until a given condition is met.
While

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Recursion

A

Recursion is a programming construct in which a subroutine
calls itself during its execution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A recursive sub-routine should:

A
  • Contain a stopping condition (base case)
    -For any input value other than the stopping condition, the subroutine should call itself (recursion)
    -The stopping condition should be reachable within a finite number of times

Without these characteristics a recursive subroutine may call itself indefinitely which will result in a stack overflow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Iteration vs recursion

A
  • more memory efficient

-recursion is not very memory efficient. Every time a recursive function calls itself, the processor needs to remember where it was before it jumps to the new copy so it knows where to return later.

-The processor also needs to remember the values of all the previous variables, as they are local to those copies of the recursive function- this is done using stacks which takes up space in memory.

if a recursive subroutine calls on itself too many times you may run out of memory and cause a stack overflow which will cause the program to crash.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

local variable main points

A
  • declared inside a subroutine
    -only accessible by that subroutine
    -created when the subroutine is called
    -destroyed when the subroutine ends
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

global variable main points

A
  • declared at the top of the program, outside of any subroutine
    -accessible throughout the program
    -created when the program starts
    -destroyed when the program ends
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is a local variable

A

Local variables have limited scope which means that they can only be accessed within the subroutine in which they were defined. Therefore, multiple local variables with the same name can exist in different subroutines.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Global variable

A

Global variables, on the other hand can be accessed across the whole program. These are useful for values that need to be used by multiple parts of the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Advantage to local variables

A

Using local variables is considered to be good programming practice because it ensures subroutines are self-contained, with no danger of variables being affected by code outside of the suoroutine.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Disadvantage to global variables

A

using global variables is not recommended because they can be unintentionally overwritten. As global variables are not deleted until the program terminates, they require more memory than local variables which are deleted once the subroutine has been completed.

• Excessive, unnecessary use of global variables can make programs hard to test, debug and maintain.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

give two advantages of using local variables over global variables

A

-less memory is used
-self contained so unaffected by code outside of the subroutine
- take procedure over global variables with the same name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is modularity

A

Modularity is the concept of breaking a large program or problem down into smaller chunks.

The goal is to design a program in such a way that each module carries out a single, specific task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Procedures

A

• A procedure is a block of code that takes in zero, one or more parameters and performs a set task

17
Q

Function

A

A function is a block of code that takes in zero, one or more parameters; performs a set task; and returns a value.

18
Q

what is the difference between procedures and functions

A

Functions must always return a value while a procedure does not always have to return a value

19
Q

state two advantages of recursion

A

• can be represented in fewer lines of code

-Easier to express some functions recursively than using iteration

20
Q

state a disadvantage of recursion

A

-inefficient use of memory

-danger of stack overflow from it calling itself repeatedly which would cause the call stack to run out of memory this would cause the program to crash

-difficult to trace

21
Q

state two advantages of a modular design

A

-makes a problem easier to understand and approach

-simpler to divide tasks between a team.

-easier to manage project

-self contained modules simplify testing and maintenance

-greater reusability

22
Q

what does it mean to pass a parameter to a subroutine by reference

A

• When a parameter is passed by reference, a pointer that contains the memory address of the original variable is created.

This then means
the address in memory of the parameter is passed to the subroutine so its value outside of the subroutine will be updated

23
Q

Passing parameters by value

A

When a parameter is passed by value, the value created for the subroutine being called is a copy of the original.

• Once it is passed in, the parameter is held in a separate memory location
and therefore, it is only available to that subroutine.

• The copy is now a local variable of that subroutine.

24
Q

What is an IDE

A

• An IDE is a program that provides a set of tools and related functionality designed to maximise a programmer’s productivity

25
Q

Ide features

A

-Code editors
-Error diagnostics
-Runtime environments
-Translators
-Auto-documentation
-Syntax highlighting
-Autocompletion

26
Q

Code editors

A

• A text area for programmers to enter code directly into the IDE; often supports additional features like syntax highlighting, autocomplete and automatic indentation.

27
Q

Error diagnostics

A

• Reports errors (mainly syntax) in the code and where they can be found; often suggests possible fixes.

28
Q

Run-time environments

A

• Software that supports the execution and running of programs.

• Allows programmers to easily run code during development.

29
Q

Translators

A

• A program that converts high-level code into executable machine code.

30
Q

Auto-documentation

A

• Tracks variables declared by the programmer, modules and other special programmer comments with a view to producing documentation that aids in program maintenance, debugging and support.

31
Q

what is top down design

A

A technique used to modularize programs in which the problem is continually broken down into sub problems, until each can be represented as an individual, self-contained module which can preforms a certain tasks