1.2.4 types of programming languages Flashcards
what are programming paradigms
Different approaches to using a programming language to solve problems.
which two broad categories are programming paradigms split into
-imperative
-declarative
Imperative programming paradigms
uses code that clearly specifies the actions to be
performed
Declarative programming paradigms
focuses on stating the desired result rather than the exact series of instructions that need to be performed to get to the result. . It is the role of the programming language to determine how best to obtain the result and the details about how it is obtained are abstracted from the user.
Advantages of procedural programming
-can be applied to a wide range of problems
- relatively easy to write and interpret
procedural programming
This is a type of imperative programming which uses a sequence of
instructions which may be contained within procedures. These instructions are carried out in a step-by-step manner.
state a use of declarative programming
-Artificial intelligence
-expert systems/knowledge based systems
identify the 4 main structures used in structural programming
-sequence
-selection
-iteration
-recursion
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.
what is procedural programming suited for
suited to problems that can easily be expressed as a series of instructions
how does assembly language differ from machine code
Assembly language uses mnemonics rather than binary. One line in assembly language is equal to one line in machine code
mnemonics
state the function of opcode and operand
the opcode specifies the instruction to be preformed and addressing mode. The operand holds a value which is related to the data on which the instruction is to be preformed
state 4 addressing modes
-immediate addressing
-direct addressing
-indirect addressing
-indexed addressing
Immediate Addressing
The operand is the actual value upon which the instruction is to be performed, represented in binary. So the memory does not need to be searched to find the required value
Direct Addressing
The operand gives the address which holds the value upon which the instruction is to be performed. Direct addressing is used in LMC.
Indirect Addressing
The operand gives the address of a memory location 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. This is necessary to add an offset in order to access data stored contiguously in memory such as in arrays
Advantages of oop
-oop allows for high level of usability which makes it useful for projects with many components
-classes can be used across multiple projects
-There is a high level of abstraction and it is not necessary for programmers to know details about how code is implemented.
-The modular structure used in OOP makes it easy to maintain and update.
-Encapsulation is a key reason for choosing OOP as it makes the code more reliable by protecting attributes from being directly accessed.
Polymorphism
Ability for methods of the same name to be used in inherited classes with different behaviours exhibited
Inheritance
Inheritance is when a class takes on the methods and attributes of a parent class. The inheriting class may override some of these methods/attributes and may have additional extra methods and attributes of its own
Class
A template defining methods and attributes used to make objects
Encapsulation
The hiding of the implementation of a class and controlling access to its methods and attributes
Object
An object is an instance of a class
disadvantages of OOP
- This is a different style of programming and so requires an alternative style of thinking. This can be difficult for programmers accustomed to other paradigms to pick up.
- OOP is not suited to all types of problems. Where few components are reused, OOP may in fact result in a longer, more inefficient program.
- Generally unsuitable for smaller problems.
overriding
Overriding is redefining a method within a subclass and altering the code so that it functions differently and produces a different output.
Overloading
Overloading is passing in different parameters into a method. Both of these forms of polymorphism would produce different results which would depend on the scenario
Assembly language
Assembly language is the next level up from machine code
and is part of a family of low level languages. This is converted to machine code using an assembler when it is executed. Assembly language uses mnemonics rather than binary, which makes it easier to use than direct machine code.
getter and setters
● A setter is a method that sets the value of a particular attribute
● A getter is another special method used in OOP which retrieves the value of a given
attribute
● Getters and setters ensure attributes cannot be directly accessed and edited but
can only be altered by public methods. This is called encapsulation.
● Every class must also have a constructor method which allows a new object to be
created