221-programming-techniques Flashcards

1
Q

Computer program

A

series of statements (instructions) that are executed (run) one after the other
- accept input, process data, produce output

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

Programming constructs

A

controls the flow of the program
iteration sequence, selection

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

sequence

A

the order of which code statements are executed
from top to bottom until the end of the program is reached/another construct
- important as carrying out instructions in wrong order lead to incorrect performing

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

selection

A

changes program flow based on outcome og logical decision e.g if statements
allows program to branch as
section of code is only run if condition is met

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

iteration

A

loops used to repeat sections of code for execution

count controlled e.g for loop - for a certain amount of time, required iterations is known ahead of time

condition controlled e.g while loop - until condition is met, when number of iterations is not known

  • simplifies program, fewer lines of code, less error prone
  • more flexible, can just change loop value to change number of iterations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

nesting

A

putting one statement inside of another, achieved by either iteration or selection/both

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

recursion

A
  • a function that calls itself within itself
  • for any input value other than stopping condition, it should call itself
  • the stopping condition should be finitely reachable or else stack overflow (indefinite calls)
  • each call creates a stack frame (new instance of a function with its own copy of local variables and parameters and return address - code point)
  • frames placed on the stack
  • then stopping, they pop off until stack emptied, return results are cascaded down to caller until initial caller
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

recursion pros and cons

A
  • more quick to read, easier to represent/ less lines of code as some functions/problems are naturally recursive
  • suited to certain problems e.g tree traversal and some sorts
  • can reduce the size of the problem each call e.g divide and conquer
  • deep -> runs out of stack space if too many calls and crash occurs (overflow)
  • more difficult to trace flow and debug, each function on the stack has its own set of variables
  • less intuitive for those unfamilar
  • inefficient use of memory
  • can be slower as overhead stack maintenance
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

call stack

A

stores the local variables, parameters, and the return address when a function is called
when functions complete execution, they are popped off

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

iteration pros and cons

A
  • more memory efficient, requires less
  • no stack overflow
  • easier to understand, debug read, and trace as straightforward
  • recursive declares new variables/stack push, iterative uses the same variables
  • for problems that can be naturally expressed iteratively
  • more lines of code, potentially harder to understand when implemented to recursive problems (representation)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

tail recursion

A
  • keeps an accumulated total of the value we are calculating
  • usually using a accumulator parameter
  • reduces computation, no additional calculations after recursive call returns as final recursive return value is the final return value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

variable

A

labelled memory location (identifier) that stores value that can be changed during running time

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

constant

A

labelled memory location whose value remains fixed
does not change during program running
must be set when written

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

assignment

A

supplies a value to constant or variable, performed with a = symbol

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

scope

A

global or local
refers to the section of code for which variable is available in when declared

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

global variable

A

-can accessed/changed throughout entire program. useful for values need to be used by multiple parts
- declared global/ in main body at top, simple.
- good practice to avoid global variables e.g if 2 functions try to access global variable at same time, conflicts and cluttered namespace
- harder to test, debug, maintain, returning values much safer
-created when program starts, destroyed when end, more memory alloc

17
Q

local variable

A

declared within function/procedure
can only be accessed within that block
- memory efficient, released from memory
- reusability: multiple same names can exist in different subroutines, unaffected
- self contained and encapsulated, no unintended outside changes
-if local variable has same name as global, local precedence
- code redundancy, same purpose/value across subs

18
Q

modularity

A

functions and procedures
- goal each module carries out specific individual task
- split large complex programs into sub self contained smaller (breaks down and structures)

19
Q

subroutines

A

section of code that performs a specific task, can be called whenever needed
given a unique name identifier
- problem shorter n easier to understand solve read debug, simplifies testing isolation, parallel team division time save, individually, reusability and existing libraries, avoid repetition, abstraction

19
Q

procedure vs function

A

both performs specific task when called
procedure does not return any value, function does
both can have any many parameters. are subroutines

20
Q

parameter vs argument

A

Parameters are variables initalised in the function’s definition for it to accept inputs. Specifies what function expects. Act as placeholder for the values (arguments) when called
Argument are the values passed into function/procedure filling the parameters
- by reference or value
- reference is address of original value, og value updated if any changes made
- value is copy of og value, treated as a local variable, new space for it and end discarded, og value outside not affected

21
Q

string manipulation

A

stringname.length

conversion
stringname.upper()
stringname.lower()
ord(”A”) gives ASCII, can use ASC
chr(65) gives char

boolean
stringname.isupper()
stringname.islower()

22
Q

file manipulation pseudocode

A

file=openWrite(“s.txt”)
file=openRead(“s.txt”)
file.writeLine(“Hello”)
file.close()
x =file.readLine()
while NOT file.endOfFile():
print(myFile.readLine()

23
Q

IDE (integrated developer environment)

A

software/ program used to write code
provides tools and features to help developer write, test, debug
editors, error diagnostics, run time environment, translator
speed up development and productivity
suitable for beginners, simple
autocompletion/indentation, syntax highlighting, integrated debugger

24
breakpoints
allows developer to define certain points in program to pause execution on condition/line helps pinpoint and identify logic errors
25
stepping
step through/execute code line by one at a time to locate error and monitor effect of each line Variable checks shows the values of the variables currently stored in memory whilst stepping through the code, observe how contents change real time
26
runtime environment
infrastructure supports execution and running of code, enable developer to check for runtime errors and test program without fully compiling it
27
auto documentation
analyse source code tracks declared variables, modules, comments - produces documentation to aid in maintenance, debugging, support
28
syntax highlighting
easier to read/identify syntax errors as coding
29
error diagnostics
diagnostics displays full report on syntax and runtime errors during and location during compilation, sometimes suggests fixes
30
syntax completion
as you type, suggests/correct code quicker to type, less errors
31
code editor
area to write and edit source code often supports additions like autocomplete, autoindent, syntax highlighting
32
operator
character that represents an action e.g +