1.2.4 Types of Prog Languages Flashcards
Procedural
-Sequence, selection, iteration
-Code developed in a modular way
-Blocks of code identify set tasks that need to be completed, utilising procedures and functions
Sequence, selection, iteration, recursion
*Sequence: Code executed line-by-line, from top to bottom
*Selection: A certain block of code is run if a specific condition is met
*Iteration: A block of code is executed a certain number of times or while a condition is met
*Recursion: Functions are expressed in terms of themselves and call themselves until a stopping condition is met (base case)
What is a pre-defined function?
Functions pre-written within a programming language
What is a local variable?
A variable that can only be accessed within the specific procedure or function it was declared in
What is a global variable?
Variable that can be accessed throughout the entire program and used by all modules
What is parameter passing
Allows variable values to be passed into procedures and functions for use in blocks of code
What is modularity?
The concept of separating the functionality of a program into individual, interchangeable blocks, each designed to carry out a single task. These all combine to make a complete program and make the program and make the program more readable
What is a library?
A collection of pre-built functions and procedures that can be linked and used by a programmer in their own code
Assembly language
-Next level up from machine code
-Converted into machine code using an assembler when code is executed
-Each instruction equivalent to one line of machine code
What system is assembly language useful in?
-Commands in assembly language are processor-specific as it directly interacts with the CPU’s special purpose registers; direct interaction of hardware THEREFORE
**Useful in embedded systems
Modes of addressing
*Machine code instructions made up of opcode and operand
*Opcode- specifies the instruction to be performed
*Operand- Holds a value which is related to the data on which the instruction is to be performed
**Addressing modes allow for a greater number of locations for data to be stored as the size of the operand would otherwise constrain the number of addresses that could be accessed
Immediate addressing
Operand is the actual value upon which the instruction is to be performed, represented in binary
Direct addressing
Operand gives the address which holds the value upon which the instruction is to be performed, used in LMC
Indirect addressing
Operand gives the address of a register which holds another address where the data is located
Indexed addressing
-An index register is used which stores a certain value.
-The address of the operand is determined by adding the operand to the index register
–Necessary to add an offset in order to access data stored contiguously in memory e.g. arrays
OOP- what is a class?
A template for an object.
Defines the state and behaviour of the object
State (properties) is given by attributes and behaviour is defined by methods associated with a class (actions it can perform)
OOP- objects
A particular instance of a class
-A class can create multiple objects with the same set of attributes and methods
-Classes create objects through the process instantiation
OOP- getters and setters
*Setter- a method that sets the value of a particular attribute (“set_reserved” would set the attribute reserved to True if someone were to reserve that book)
Getter- a method which retrieves the value of a given attribute
**Both used to ensure attributes cannot be directly accessed and edited by the user (encapsulation)
OOP- encapsulation
Attributes are declared as private so can only be altered by public methods
OOP- constructors
“new”
Allows a new object to be created
OOP- inheritance
A subclass is based on the superclass. The subclass inherits the attributes and methods of the superclass and can have its own additional properties/attributes
*Allows effective reuse of components and properties while being able to make changes
“class Biography inherits Book”
OOP- polymorphism
Objects can behave differently depending on their class.
The same method can produce different outputs depending on the object involved
*Overriding: redefining a method within a subclass and altering the code so that it functions differently and produces a different output
*Overloading: passing in different parameters into a method
Advantages of OOP
*Allows for a high level of reusability, makes it useful for projects where there are multiple components with similar properties (inheritance and polymorphism)
*Classes can be used across multiple projects
*Encapsulation makes code more reliable by protecting attributes from being directly accessed. Code for different classes can also be produced independently of others
*Requires advanced planning to determine how the problem will be broken down into classes etc; a thorough design can produce higher-quality software with fewer vulnerabilities
*Modular structure makes it easy to maintain and update
*High level of abstraction
Disadvantages of OOP
-Requires an alternative style of thinking; can be difficult for programmers accustomed to other paradigms to pick up
-Not suited to all types of problems; where few components are reused, OOP may result in a longer, more inefficient program
-Generally unsuitable for smaller projects