Programming Paradigms Flashcards
Which programming paradigm emphasizes the use of pure functions and immutable data ?
FP
Which programming paradigm emphasizes the use of objects
OOP
How are programs constructed in FP ?
by composing pure functions that transform data without changing it.
What are the two characteristics of pure functions ?
pure functions have no side effects and always return the same output given the same input.
What are the consequences of coding using FP ?
code that is easy to reason about and test,
What are higher order functions ?
functions that take other functions as inputs or return functions as outputs.
Name 3 main characters in regards to the story of the FP paradigm
- pure functions
- immutable data
- higher order functions
what are objects ?
instances of classes that encapsulate data and behavior.
Name 3 main concepts highlighted via OOP
- abstraction
- inheritance
- polymorphism
what is abstraction ?
process of hiding complexity by exposing only relevant information to the user.
what is inheritance ?
process of classes inheriting properties and methods from other classes.
what is polymorphism ?
objects of different classes to be used interchangeably, as long as they have a common interface.
how is data and state managed in FP ?
data is immutable and state changes are managed through the creation of new data structures.
how is data and state managed in OOP ?
data is encapsulated within objects and state changes are managed through methods that mutate the object’s internal state.
how is control flow managed in FP?
control flow is managed through the composition of functions using higher-order functions.
how is control flow managed in OOP ?
control flow is managed through method calls and object interactions.
how is encapsulation managed in FP ?
functions are pure and have no side effects, so there is no need for encapsulation.
What is encapsulation ?
Encapsulation provides a way to control access to the internal state of an object and helps prevent external code from directly manipulating its data
how is inheritance managed in OOP ?
inheritance is used to create new classes that inherit properties and methods from other classes.
how are complex programs created in FP ?
composition is used to combine functions and data structures to create more complex programs.
what is a HOF ?
A higher-order function is a function that takes one or more functions as arguments or returns a function as its result.
how can you build complex functions via HOFs ?
Higher-order functions are used to build complex functions by combining simpler functions.
why is immutability important in FP ?
because it makes it easier to reason about the behavior of the program and helps to prevent bugs.
what is recursion ?
Recursion is a technique where a function calls itself.
why is recursion often used in FP ?
Recursion is often used in functional programming because it is a natural way to express computations that involve repeated calculations.
what is a monad ?
A monad is a design pattern used to manage side effects in functional programming.
why is a monad is a way to encapsulate a computation that has side effects ?
so that the side effects can be managed and controlled.