2.2.1 programming techniques

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/35

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

36 Terms

1
New cards

sequence

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

2
New cards

branching

  • a certain block of code is run if a specific condition is met, using IF statements

  • also known as ‘selection

3
New cards

iteration

  • a block of code is executed a certain number of times or while a condition is met

  • Iteration uses FOR or WHILE loops

    • count-controlled Iteration is repeated a given number of times

      • for i in range (0,10): 

      • print i

    • condition-controlled Iteration continues until a given condition is met

      • while i <= 20: 

      • print “Not true”; 

      • i=i+1 

      • endwhile  

4
New cards

recursion

  • a programming construct in which a subroutine calls itself during its execution

  • this continues until a certain condition - called the stopping condition / base case - is met, at which point the recursion stops

5
New cards

ADV recursion

  • represented in fewer lines of code, which makes them less prone to errors

  • however it is essential that recursive subroutines are clearly defined so as to reach a stopping condition after a finite number of function calls

6
New cards

DIS recursion

  • inefficient use of memory

    • if the subroutine calls itself too many times, there is a danger of a stack overflow, which is when the call stack runs out of memory

    • this would cause the program to crash

  • recursion is difficult to trace, especially with more and more function calls

7
New cards

local variables

  • they can only be accessed within the block of code in which they were defined

  • if a local variable is defined within a subroutine, it can only be accessed within that subroutine

  • ensures subroutines are self-contained, with no danger of variables being affected by code outside of the subroutine

  • destroyed when the subroutine exits

8
New cards

global variables

  • global variables can be accessed across the whole program

  • all variables used in the main body of a program are automatically declared to be global

  • useful for values that need to be used by multiple parts of the program

  • 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

9
New cards

modular programming

  • technique used to split large, complex programs into smaller, self-contained modules

  • a modular design also makes it easier to divide tasks between a team and manage, whilst simplifying the process of testing and maintenance, as each component can be dealt with individually

  • improves the reusability of components, as once a module has been tested, it can be reused with confidence

10
New cards

modular programming - top down approach

  • problem is continually broken down into sub-problems, until each can be represented as an individual, self-contained blackbox which performs a certain task

  • also known as stepwise refinement

  • these modules form blocks of code called subroutines, which can be categorised as either functions or procedures

<ul><li><p>problem is continually broken down into sub-problems, until each can be represented as an individual, self-contained blackbox which performs a certain task </p></li><li><p>also known as stepwise refinement</p></li><li><p>these modules form blocks of code called subroutines, which can be categorised as either functions or procedures</p></li></ul><p></p>
11
New cards

procedures

  • a self contained block of code that preforms a specific task

  • doesn’t have to return a value

  • can return multiple values

  • typically given data as parameters for manipulation

12
New cards

functions

  • self contained block of code that preforms a specific task

  • must always return a value

  • must return a single value

  • makes use of local variables

13
New cards

parameter

variable inside the implementation of the subroutine

14
New cards

passing by value

  • the value created for the subroutine is a copy of the original

  • once it is passed in, the parameter is held in a separate memory location

    • therefore is only available to that subroutine

  • the copy is now a local variable of that subroutine

    • its value outside the subroutine will not be affected

15
New cards

passing by reference

  • a pointer that contains the memory address of the original value is created

  • any changes to that value from within the called subroutine will also affect the value of the original variable

16
New cards

IDE def

  • Integrated Development Environment

  • a program which provides a set of tools to make it easier for programmers to write, develop and debug code

17
New cards

features of an IDE

  • stepping

    • allows you to monitor the effect of each individual line of code by executing a single line at a time

  • variable watch

    • sometimes used to pinpoint errors, this is a useful feature to observe how the contents of a variable change in real-time through the execution of a program

  • breakpoint

    • allow users to set a point in the program at which the program will stop.

    • can either be based on a condition or set to occur at a specific line.

    • help to pinpoint where an error is occurring

  • debugging

    • tools Some IDEs also provide run-time detection of errors with a guide as to where in the code they are likely to have occurred through line numbers and highlighting

  • auto complete

    • start typing a command and it fills in the rest

  • auto indent

    • indents code automatically within structures to avoid errors

18
New cards

class

  • a template for objects

  • defines a data structure by providing initial values for attributes and methods

19
New cards

attribute

characteristics of a class that can be accessed by other objects

20
New cards

method

  • a function that is defined inside a class and typically operates on objects of that class

  • used to manipulate the attributes of an object and perform operations on it

21
New cards

object

an instance of a class

22
New cards

encapsulation

bundling of data with the methods that operate on the data

23
New cards

ADV of reusable components

  • saves time from having to write the same algorithm again

  • reduced testing requirements

24
New cards

aggregation

relationship between two classes where one class contains or is composed of one or more objects from another class

25
New cards

composition

  • implements a has-a relationship between classes

  • one class contains 1 or more objects from another class

26
New cards

polymorphism

allows you to work with objects of different types though a common interface

27
New cards

inheritance

  • capability to derive a class properties and characteristics from another class

  • implements an is-a relationship between classers

28
New cards

constructor

creates an instance of an object from a class

29
New cards

operators

=,+=,<,>

30
New cards

use of validation

check to ensure that data entered is sensible and feasible

31
New cards

variable

something that can hold a value

32
New cards

branching

allow the flow of execution to jump to a different part of the program if a specific condition is met

33
New cards

procedural programming

statements are executed in the order they are written

34
New cards

object orientated programming

  • designed around objects rather than functions

  • objects represent real-world entities and have attributes (data) and behaviours (methods)

  • promotes modularity, code reuse, and scalability

35
New cards

variable

  • Name (Identifier) – A unique name assigned to the variable e.g. user_age

  • Data Type – Specifies what kind of value the variable can hold e.g. boolean

  • Value – The actual data stored in the variable, which can change during execution

  • Memory Location – The address in memory where the variable’s value is stored

  • Scope – Defines where in the program the variable can be accessed e.g. local, global

36
New cards

instantiation

the process of creating an object (or instance) from a class