Unit 12 - OOP and Functional Programming Flashcards

(44 cards)

1
Q

What is a programming paradigm?

A

A programming paradigm is a style of programming.

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

What is imperative programming?

A

Imperative programming is a programming paradigm that focuses on describing how a program operates step by step.

The code directly controls execution flow and state change, explicit statements that change a program state.

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

What is the procedural paradigm?

A

A form of imperative programming which uses functions, modules, procedures and other forms of structuring to describe the step-by-step operations of a program.

The code is organized as procedures that call each other.

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

What is the Object-oriented paradigm?

A

A form of imperative programming which is organized as objects that contain both data structure and associated behaviour, uses data structures consisting of data fields and methods together with their interactions to design programs.

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

What is the Declarative paradigm?

A

A form of non-imperative programming in which code declares properties of the desired result, but not how to compute it, describes what computation should perform, without specifying detailed state changes.

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

What is the Functional paradigm?

A

A form of non-imperative programming in which a desired result is declared as the value of a series of function evaluations, uses evaluation of mathematical functions and avoids state and mutable data.

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

What is a function in functional programming?

A

A function is a mapping from a set of inputs, called the domain, to a set of possible outputs, known as the co-domain.
They are first-class objects.

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

What is the domain in functional programming?

A

The domain is a set from which the function’s input values are chosen.

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

What is the co-domain in functional programming?

A

The co-domain is a set from which the function’s output values are chosen.

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

What is composition of functions in functional programming?

A

Using one function as an argument of another, is called composition of functions.

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

What is a first-class object?

A

These are objects which may appear in expressions, be assigned to a variable, be assigned as an argument or be returned in a function call.

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

What is statelessness in functional programming?

A

In a functional programming language, the value of a variable cannot change as there are no states, i.e. there is no before or after.

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

What is the only thing a function can do in functional programming?

A

The only thing a function can do is calculate something and return a result, and it is said to have no side effects.

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

What is function application?

A

The process of giving particular inputs to a function.

Partial function application is where a function is given a specific input in its definition rather than letting them all be assigned by the user.

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

What is a higher-order function?

A

A function is higher-order if it takes a function as an argument or returns a function as a result, or does both.

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

What is the map function?

A

Map is a higher-order function that takes a list and the function to be applied to the elements in the list as inputs, and returns a list made by applying the function to each element of the old list.

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

What is a list in functional programming?

A

A list is a collection of elements of a similar type, such as integers, characters or strings, which can be written in square brackets. A list is composed of a head and a tail. The head is the first element of the list, and the tail is the remainder of the list. They are immutable as with every other variable.

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

What is the filter function?

A

filter is another higher-order function which takes a predicate (to define a Boolean condition) and a list. It returns the elements within the list that satisfy the Boolean condition.

19
Q

What is the fold function?

A

A fold (or reduce) function reduces a list to a single value, using recursion. The initial value is combined with the first element of the list, which is then recursively combined with the first element of the remaining list, and so on.

Fold functions can start with either the left or right most part of a list.

20
Q

What are the basic list functions?

A
  • head() - returns the head of a list,
  • tail() - returns the tail of a list,
  • Null() - returns True if list is empty, False otherwise,
  • length() returns the number of elements in a list,
  • prepending - adding an element to the front of a list, uses the : operator,
  • appending - adding an element to the end of a list, uses the ++ operator,
  • concatenation - combining two lists to make one list,
  • concat() - concatenates the elements in a list and returns one element.
21
Q

What is Big Data?

A

‘Big Data’ includes data that is collected on such a large scale that it cannot easily be analysed.

22
Q

What are the three distinguishing characteristics of Big Data?

A

The three distinguishing characteristics of Big Data are:
- volume – too big to fit on a single server,
- velocity – there is only milliseconds or seconds to respond, particularly with streamed data,
- variety – the data may be in many forms such as structured, unstructured, text, multimedia.

23
Q

What are the features of functional programming which make it useful for working with Big Data distributed across multiple servers?

A
  • Large datasets require distributed processing: FP aids the production of correct and efficient distributed code.
  • Immutable data structures, which cannot be inadvertently altered in a function.
  • Statelessness, so the program’s behaviour does not depend on the order in which functions are called.
  • Higher-order functions such as map and fold allow functions to be input as argument and these can be efficiently parallelised allowing many processors can work simultaneously on parts of a dataset without affecting other parts.
24
Q

What is the fact-based model?

A

A data representation approach that focuses on immutable facts: pieces of data that cannot be further deconstructed and remain eternally true.

25
Why is the fact-based model used for big data?
Traditional data processing involving relational databases does not suit either the volume or the variety of Big Data.
26
Why does big data require machine learning techniques?
Big Data needs machine learning techniques to find patterns, because it lacks structure.
27
What do objects in object-oriented programming consist of?
Each object has its own data (attributes) and operations on that data (methods).
28
What is a class in object-oriented programming?
A class is a blueprint for an object which defines attributes and methods that capture the common characteristics and behaviours of objects.
29
What is a constructor in object-oriented programming?
A constructor is used to create objects based on a class.
30
What is encapsulation?
Attributes and methods are wrapped into a single entity.
31
How is information hiding present in Object-oriented programming?
- An object’s attributes are hidden (private), - Its attributes are accessed and changed only through the object’s methods, - Methods are required to set (setters) and retrieve (getters) an object’s attributes, - To interact with an object, its methods must be accessible (public).
32
What is instantiation in object-oriented programming?
Creating an object from a class blueprint.
33
What is inheritance in object-oriented programming?
Creating a new class based on an existing class (superclass). The new class is a subclass of the superclass. The subclass inherits all the attributes and methods of the superclass and has some of its own attributes and / or methods
34
What is polymorphism in object-oriented programming?
A method used in a class hierarchy can behave differently in each class. This is achieved through overriding: a method with the same identifier in the superclass can be redefined or extended in a subclass.
35
What the access modifiers in object-oriented programming?
- Private – Accessible only within the same class. Used to hide sensitive data and enforce controlled access via public methods. - Protected – Accessible within the same class, subclasses, and sometimes same package (language-dependent). - Public – Accessible from anywhere in the program.
36
What is association in the context of object oriented programming?
Association defines a relationship between classes of objects that allows one object instance to cause another to perform an action on its behalf. This relationship is structural, because it specifies that objects of one kind are connected to objects of another and does not represent behaviour.
37
What is composition in the context of object oriented programming?
A form of association where if the containing object is destroyed so are the objects it contains​. - Depicted as a filled diamond and a solid line on diagrams.
38
What is aggregation in the context of object oriented programming?
A form of association where The objects remain when the container object is destroyed​. - Depicted as an unfilled diamond and a solid line on diagrams.
39
What is an abstract method in the context of object oriented programming?
A method which: - consists of only a signature and no implementation​, - is used to specify that a subclass must provide an implementation of the method​, - is used to specify interfaces in some computer languages.
40
What is an static method in the context of object oriented programming?
A method which: - is relevant to all the instances of a class rather than to any specific instance​, - has no owning object and does not run on an instance​, - receives all information from its arguments.
41
What is an virtual method in the context of object oriented programming?
A method in which: - implementation can be redefined by subclasses.
42
What is an interface in the context of object oriented programming?
A collection of methods with no implementation​, - Is a set of public method signatures​, - Cannot include any implementation or data properties​, - Reduces dependency on implementation specifics and makes code more reusable​, - Generally only used in languages that use the single-inheritance class model. Python supports multiple inheritance, so does not use interfaces but uses base classes or abstract base classes​.
43
What are some advantages of the object-oriented paradigm?
- Extensive planning phase makes for better designs​, - Source code for object is written and maintained independently of other objects​, - Programmers can use existing objects without needing to know how they were implemented​, - Good framework for code libraries​, - Software maintenance easier because of rigidly enforced modular structure​.
44
What is the difference between composition and inheritance?
Composition is a less rigid relationship between two objects than an inheritance relationship between two objects​.