2.2.1 Programming Techniques Flashcards

1
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
2
Q

Selection

A

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

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

Iteration

A

Can be either:

Count-controlled

  • Block of code executed a certain number of times

Condition-controlled

  • Block of code is executed while a condition is met

Uses FOR, WHILE or REPEAT UNTIL loops

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

Recursion

A
  • Programming construct in which a subroutine calls itself during its execution
  • Continues until a stopping condition is met
  • produces the same result as iteration, but is more suited to certain problems
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Recursion - Advantages

A
  • Can be represented in fewer lines of code (for some problems), making them less prone to errors
  • Easier to express some functions recursively eg. Factorial
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Recursion - Disadvantages

A
  • Inefficient use of memory
  • Risk of stack overflow if memory runs out
  • Difficult to trace (especially with more and more function calls)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Variables

A
  • Variables can be defined with either global or local scope
  • Scope is the section of code in which the variable can be accessed
  • A local variable within a subroutine takes precedence over a global variable with the same name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Local Variables

A
  • Can only be accessed within the subroutine in which they were defined
  • Multiple local variables with the same name can exist in different subroutines
  • Are deleted once subroutine ends
  • Using local variables ensures subroutines are self-contained - good
    programming practice
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Global Variables

A
  • Can be accessed across the whole program
  • Useful for values that need to be used by multiple parts of the program
  • Danger of being unintentionally edited and overwritten
  • Not deleted until program terminates, so require more memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Modular Programming

A
  • A programming technique used to split large, complex programs into smaller, self-contained modules.
  • Modularity is essential to making a problem easier to understand and approach.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Benefits of a Modular Approach

A
  • Easier to divide tasks between a team and manage projects
  • Simplifies the process of testing and maintenance, as each component can be dealt with individually
  • Improves reusability of components - once a module has been tested, it can be reused with confidence
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Top-Down Approach

A
  • Technique used to modularise programs
  • Problem is broken down into sub-problems, until each is represented as an individual, self-contained module which performs a certain task
  • Modules form blocks of code called subroutines
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Functions vs Procedures

A
  • Both named blocks of code that perform a specific task
  • Procedures do not return a value
  • Functions must always return a single value (some languages, like Python, allow functions to return multiple values using tuples)
  • Parameters can be passed into a subroutine either by value or by reference
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Passing By Value

A
  • A copy of the value is passed to the subroutine and discarded at the end
  • Its value outside of the subroutine remains unaffected
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Passing By Reference

A
  • Address of parameter is given to the subroutine
  • Value of the parameter will be updated at the given address
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

IDE

A

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

17
Q

Benefits of Using an IDE to Write Code

A
  • Source Code Editor
  • Autocorrect
  • Autocompletion
  • Pretty Printing
  • Syntax Highlighting
  • Auto-documentation
  • Code Editors
  • Translators
18
Q

Source Code Editor

Benefits of Using an IDE to Write Code

A

The editor aims to make the coding process easier by providing features such as autocompletion of words, indentation, syntax highlighting, and automatic bracket completion.

19
Q

Autocorrect

Benefits of Using an IDE to Write Code

A

Automatically corrects typos and common syntax errors as you type, enhancing productivity and reducing the number of minor errors.

20
Q

Autocompletion

Benefits of Using an IDE to Write Code

A

Provides suggestions for code completion based on the context, which helps speed up coding by reducing the amount of typing and preventing syntax errors.

21
Q

Pretty Printing

Benefits of Using an IDE to Write Code

A

Automatically formats the code to be more readable with proper indentation and line breaks, making it easier to understand and maintain.

22
Q

Syntax Highlighting

Benefits of Using an IDE to Write Code

A

Uses different colors and fonts to distinguish various elements of the code (e.g., keywords, variables, strings), improving readability and helping to quickly identify errors.

23
Q

Auto-documentation

Benefits of Using an IDE to Write Code

A

Generates documentation automatically based on the code and comments, which helps keep the documentation in sync with the code and improves understanding for other developers.

24
Q

Code Editors

Benefits of Using an IDE to Write Code

A

Provide an environment for writing and editing code with features that enhance productivity, such as syntax highlighting and autocompletion.

25
Q

Translators

Benefits of Using an IDE to Write Code

A

Components like compilers or interpreters that translate the written code into machine code or bytecode that can be executed by a computer.

26
Q

Benefits of Using an IDE to Test Code

A
  • Breakpoints
  • Stepping
  • Variable Watch Window
  • Debugging Tools
  • Error Diagnostics
  • Runtime Environments
27
Q

Breakpoints

A

IDEs allow users to set a point in the program at which the program will stop. This can either be based on a condition or set to occur at a specific line. This can help to pinpoint where an error is occurring.

28
Q

Stepping

A

This allows you to monitor the effect of each individual line of code by executing a single line at a time. It’s useful for debugging and understanding the program flow.

29
Q

Variable Watch Window

A

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.

30
Q

Debugging Tools

A

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.

31
Q

Error Diagnostics

A

Tools that help identify and diagnose errors in the code, providing detailed information about what went wrong and where.

32
Q

Runtime Environments

A

Environments within the IDE that allow code to be run and tested directly, often with integrated debugging tools to monitor the execution.

33
Q

Use of Object Orientated Techniques

A
  • Object-oriented languages are built around the idea of classes
  • A class is a template for an object
  • Classes define the state and behaviour of an object
  • Object state is given by attributes while behaviour is defined by methods
  • An object is a particular instance of a class
  • Attributes cannot be directly edited in a technique called encapsulation
  • Top-down design applies encapsulation to modules, which are also built to be self-contained and reusable