1.2.4 Flashcards

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

low level and high level

A

we can sort all programming languages into 2 broad categories: H+L

Machine code: least abstract, closest to what actually happens in a computer, programs directly in 1s and 0s. Translate into matching electrical signals.
Assembly: uses mnuemincs (short words), each mnu matches specific sequence of 1s and 0s, 1-1 relationship, written in AL and translated by specific assembler.
high level: 1-m relationship, each instruction could give rise to many lines of am chine code.

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

high level languages

A

high-level programming language is written in language designed to be easily understood by humans. It uses syntax that is similar to human language to form instructions.
It must be translated into machine code before it can be run = compilation.
A single line of code can accomplish multiple tasks

easier to write programs in high-level languages than in low-level languages, syntax that is easy for humans to understand uses command words similar to natural human language.
Allow the programmer to focus on what the program is trying to achieve rather than how the computer or specific hardware operates
Source code is translated into machine code for the computer to process
portable. They can be compiled or translated to run on a wide range of computer architectures; they are not specific to a particular instruction set.
High-level languages come with libraries of functions that can be imported and used by the programmer. This means the programmer can take advantage of pre-written code.

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

Low level languages

A

Low-level languages are defined by the processor they are designed to run on; we can describe these languages as machine-oriented. They have no built-in functions and can access specific registers in the processor.

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

adv+dis of machine code and assembly code

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

programming paradigms

A

Programming paradigms are different approaches to using a programming language to solve a problem.

High level split into two broad categories - imperative and declarative - which can be broken down further into more specific paradigms.

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

imperative and declarative

A

IL use statements that change a programs state in the form of a sequence, selection, iteration etc. They consist of commands for a computer to perform and focus on describing how a program operates.

DL focus on what the program should accomplish.

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

imperative languages

A

two main paradigms that full under IL, procedural programming and object orientated programming.

Procedural programming is a type of imperative programming paradigm where a program is built from one or more subroutines (procedures, functions). Focus on telling a computer exactly what to do by way of step-by-step instructions.
It lays code out as a series of statements like sequence, selection, iteration.

OOP paradigms are a modern extension of the imperative programming approach that focuses more on a modular approach to programming.

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

Pl examples

A

Procedural languages use traditional data types such as integers and strings which are built into the language and also provide data structures like dictionaries and arrays.

Structured programming is a popular subsection of procedural programming in which the control flow is given by four main programming structures:
- Sequence
Code is executed line-by-line, from top to bottom.
- Selection
A certain block of code is run if a specific condition is met, using IF statements.
- Iteration
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.
- Recursion
Functions are expressed in terms of themselves. Functions are executed, calling themselves, until a certain condition known as a base case (which
does not call the function) is met.

So procedural programming is suited to problems that can easily be expressed as a series of instructions using the constructs described above.

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

procedural paradigms vs object oriented

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

Describe how the operating system would use virtual memory to load program C.

A

Operating system uses area of secondary storage
as virtual memory.
- Move unused pages/parts (of program A and/or B) into virtual memory
- Load program C into (physical) memory.

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

Discuss the differences between assembly code and high‑level languages

A

Assembly code uses mnemonics to represent machine code instructions/opcodes.
High level languages use more natural/mathematical notation.
Assembly code consists of simple instructions
As such many more lines of assembly code are required to perform the same task as a few lines of a high level language.
Assembly code is specific to the instruction set of a given processor. High Level languages are not architecture specific.

Assembly code allows the programmer to choose the exact instructions so they can write code that is highly efficient.
It also allows them to have direct control of how memory is used via addressing modes.
Direct control of hardware.
High level language compilers have optimisers that can also try and do this (and in some cases may outperform a human writing in assembly code).
As high level code is more intuitive and easier to read it is easier to follow, debug and build as part of a team. It can also be written in a much shorter time frame.
The high level code can be recompiled for different architectures.
High level languages come in a variety of paradigms so
programmers can choose according to the problem/their preference.

Assembly language is best suited to situations such as:
-compilers or interpreters don’t exist for the target CPU i.e. embedded systems
-highest possible performance is critical
-memory is very limited.
For larger projects which don’t fall under the constraints above high level languages are likely to be preferable

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

declarative languages

A

two paradigms fall under DL: functional and logical.

Functional programming uses the concept of reusing a set of functions, which form the core of the program. Programs are made up of lines of code consisting of function calls, often combined within each other. Closely linked to mathematics.

Logic languages use code which defines a set of facts and rules based on the problem. Queries are used to find answers to problems.

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

mnemonics

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

Once an instruction is fetched it needs to be decoded before we can execute it. Involves splitting the binary that makes up the code into opcode and operand.
The opcode specifies the instruction to be performed. The operand holds a value
which is related to the data on which the instruction is to be performed.

Addressing modes allow for a much 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. It specifies how the operand should be interpreted. The addressing mode is part of the opcode and there are four addressing modes:

  • Immediate Addressing
    The value in the address part of the instruction is actually the value to be used, so the memory doesn’t need to be searched to find the required value. e.g., add 10 is add 10.
  • Direct Addressing
    The value in the address part of the instruction is a reference to the address in memory where the required value is located. e.g., find what is in the memory address location 10 ad add it to the acc.
  • Indirect Addressing
    The value in the address part of the instruction is a reference to the memory location that contains the address in memory where the required value is located.
    This mode of addressing memory is useful since it means larger address ranges can be useful to reference data and ins.
  • 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. This is necessary to add an offset in order to access data stored contiguously in memory such as in arrays.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

OOP

A

Attempts to capture/group info, data and related code into structured items(objects). e.g. animal, car, data structure, account. Each object is repsonsible for its own data and operations performed on it. Objects interact with each other by sending/receiving messages.

adv:
once you define a class (deciding what attributes and methods it’ll have) it becomes easy to reuse that class and can create hundreds of objects of that class, also shareable to different projects
With inheritance, data analysis can be done in less time with precise bug free code
dis:
Slower programs than procedural based programs as they require more instructions to be executed

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

classes

A

blueprint used to set/define what attributes/methods an object of a certain type should have.
(Class diagram) first identifying the info and actions related to an object, e.g a light bulb: colour, type, connection.
We place them into theoir own class. Classes have three main sections:
Class name: lightbulb
Attributes: colour: string, type: string, connectiontype: string
Methods: code associated with the class that allows you to access/change its attributes ( getColour(), getType(). setColour(), setType()

17
Q

classes vs objects

A
18
Q

bringing a class to life as objects

A

e.g. a class of a toy tank: doesn’t yet reprsent a real-life instance of toy tank, just tells us what it should look like.
Instantiation- process of creating an object from a class template. You can create (instantiate) as many copies of an object as you need from a single class structure. Since the number of objects can change at run-time, objects are dynamic data structures.

19
Q

OOP code

A

class
attributes colour/name
constructor methods, when an object is instantiated (created), the constructor method takes the values of the parameter’s passed into the object and sets local attributes (colour/name) to their initial values.
four methods for the class, two for getting the tanks colour +_name, two for setting the colour + name
insatiate code that craetes three separate objects

20
Q

inheritance

A

Not every specific object is the same, will share the same attributes (variables) and methods (subroutines) but may require additional ones to fully describe them. With OOP, we can use inheritance to quickly/easily reuse the generic code from a class and extend its attributes/methods (subclass) without affecting the original code (superclass).

Instance when a subclass needs more detailed/specific version of a methods inherited from further up the class tree, we use a method of the same name in the subclass that contains more specific code reliant to that class= method from the parent class is overridden. overriding can be ignored by using the .super. prefix, e.g emplyeeFour.super.getName() would be Justin and emplyeeFour.getName() would be S_Justin.

21
Q

inheritance code

A
22
Q

encapsulation

A

Unlike records, attributes of an object can be public or private. Public attributes are like global variables and can be used and accessed by other objects. Private attributes can only be accessed/changed by methods of the object–this is known as encapsulation. Used to hide the values/internal state of an object, preventing direct access from unauthorised parties.
It helps keeps data related to an object safe, can’t accidentaly be altered by another part of the program without using the code provided in the methods, keeping programmer in control.
You must supply methods if you want an objects private attribute to be read/altered, so objects methods are normally set to public not private.

23
Q

encapsulation code

A
24
Q

polymorphism

A

something that occurs in several different forms. two main types in OOP: static and dynamic.
static: allows you to implment multiple methods of the same name, but with diffrent parameters, within the same class. (Method overloading). parameter set must differ in one of these was:
need to have different number of parameters (one two, one three)
types of parameters need to be different (one string, one integer)
expect parameters in a different order

25
Q

dynamic

A

inheritance hierarchy, a subclass can override a method of its superclass, allowing the coder of the subclass to customise the behaviour of that method.