2.7 Types of Programming Languages Flashcards
Programming Paradigms
Programming Paradigms: Different approaches to using a programming language to solve a problem
- Split into 2 categories - imperative & declarative which can be broken down further
- The paradigm used depends on the type of problem that needs solving
Imperative Paradigm
Imperative: Code that clearly specifies the actions to be performed
Procedural Programming: Can be applied to a wide range of problems, easy to write & interpret
- Uses sequence of instructions which may be contained within procedure
- Instructions carried out step-by-step
Object-Oriented: Applicable to problems w/ lots of reusable components w/ similar
characteristics
- Built on objects formed from classes which have certain attributes & methods
- OOP focuses on making programs that are reusable & easy to update & maintain
Declarative Paradigm
Declarative Programming: Focuses on stating the desired result rather than the exact series of instructions that need to be performed
- Role of the programming language to determine how best to obtain the result & the details about how it is obtained are abstracted from the user
- Common in expert systems & artificial intelligence
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: Part of declarative programming paradigm
- Code which defines a set of facts and rules based on the problem
- Queries are used to find answers to problems
Procedural Programmig
Procedural Programming: Used for wide range of software development, very simple to implement
- However, not possible to solve all kinds of problems, or may be inefficient
- Use traditional data types such as integers & strings which are built into the language
- Provide data structures (e.g dictionaries & arrays)
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. Uses FOR or WHILE loops
Recursion: Functions are expressed in terms of themselves. Functions are executed,
calling themselves, until base case (which does not call the function) is met
Procedural programming suited to problems that can easily be expressed as series of instructions using the constructs described above
Assembly Language
Assembly Language: Next level up from machine code, low level language
- Converted to machine code using assembler
- Uses mnemonics , easier to use than direct machine code
- Commands are processor-specific, directly interacts w/ CPU’s registers
- Allows for direct interaction w/
hardware, useful in embedded systems
- 1 instruction in assembly language = 1 line of machine code
OOP
Class: Template for an object, defines the methods & attributes of an object
Methods: Give an object’s properties
Attributes: Defined by the methods associated with a class, which describe the actions it can perform
Instantiation: Classes used to create objects
Object: Instance of a class
- Class can be used to create multiple objects with same attributes & methods
Setter: Method that sets the value of particular attribute
Getter: Method which retrieves value of given attribute
- Constructor Method: Allows a new object to be created.
Encapsulation
Encapsulation: Attributes cannot be directly accessed & edited by users
- Attributes declared as private so can only be altered by public methods
Inheritance
Inheritance: Class inherits from another class
- Subclass (or derived class)possesses all methods & attributes of superclass (parent class)
- Can have own additional properties
- Allows programmers to effectively reuse components & properties while making changes
Polymorphism
Polymorphism: Objects behave differently depending on their class
- Can result in same method producing different outputs depending on object involved
- 2 types of polymorphism: Overriding & Overloading
- Overriding: Redefining a method within subclass & altering code so that it functions differently & produces different output
- Overloading: Passing in different parameters into a method
- Both of these would produce different results, depend on scenario
Advantages & Disadvantages Of OOP
Advantages:
- Allows for reusability, useful where there are multiple components with similar properties
- Classes can be used across multiple projects
- Encapsulation, makes code more reliable by protecting attributes from being directly accessed
- Requires advance planning, produces high quality software
- Modular structure, easy to maintain and update.
Disadvantages:
- Requires alternative style of thinking, difficult if used to others
- Not suited to all types of problems. E.g Where few components are reused
- Unsuitable for smaller problems