Paradigms are a way of classifying the writing of code based on certain factors. Languages can be classified into various paradigms.
some paradigms are:
- imperative that the programmer instructs the machine how to change its state,
- procedural that groups instructions into procedures,
- object-oriented, which groups instructions with the part of the state in which they operate,
- declarative in which the programmer merely declares properties of the desired result, but not how to calculate it
- functional where the desired result is declared as the value of a series of function applications,
- logic in which the desired result is stated as the answer to a question about a system of facts and rules,
- mathematics in which the desired result is declared as the solution to an optimization problem
- reactive where the desired result is declared with data streams and change propagation
Your answer should be something like:
Good to know:
- Prototype-based programming is an object-oriented style of programming in which behavior reuse is accomplished through a process of reusing existing objects that serve as prototypes.
- functional programming is a programming paradigm that treats computation as an evaluation of mathematical functions and that avoids mutable states or data. It emphasizes the application of functions, in contrast to imperative programming, which emphasizes changes in program state.
2 - What is Functional Programming?
Functional programming is a programming paradigm. In other words, it's a way of thinking about writing software based on specific principles that have been defined and listed below. Other examples of programming paradigms include object-oriented programming and procedural programming.
The main concepts:
Pure functions: Dadas as mesmas entradas, sempre retorna a mesma saída, e Não tem efeitos colaterais.
Function composition: is the process of combining two or more functions to produce a new function or perform some calculation. No side effects
Avoid shared state: shared state is any variable, object or memory space that can be changed in more than one place or by more than one function. The idea is to avoid states like this to avoid bugs. A function can be called in many different states and can downgrade or downgrade that state.
Avoid mutating state: Immutability and create objects that cannot be changed once created. This is the central concept of functional programming
Avoid side effects: A side effect is any change in application state that is observable outside of the called function other than its return value. Side effects include Modifying any external variable or object property (for example, a global variable or a variable in the parent function's scope chain), writing to the console, printing something to the screen, writing to a file, sending something to the network , trigger any external process, call any other function with side effects.
Good to know: in a reduced way functional programming can be understood as: the process of building software through the composition of pure functions, avoiding sharing of states, mutable data and side effects. - in case you need to memorize the concept more easily, this is the definition to follow.
3 - What is the difference between class inheritance and prototypal inheritance (classical inheritance and prototypal inheritance)
- Class inheritance: In classic object-oriented programming languages, objects are abstractions of real-world entities and classes are generalizations (that is, abstractions of objects or other classes). Instances are typically instantiated through constructor functions with the keyword "NEW"
- Prototypical inheritance: In prototypical object-oriented programming languages, objects are abstractions of real-world entities or other objects. So a prototype is a generalization. Instances are typically instantiated through factory functions or Object.create(). Instances can be made up of many different objects, allowing for easy selective inheritance.
4. What are the advantages and disadvantages of functional programming vs object-oriented programming?
Object Oriented Pros:
It's easy to understand the fundamentals of objects and explain the meaning of method calls. Object Oriented tends to use the imperative rather than the declarative. It looks like a series of simple instructions that a computer must follow.
Object orientation usually depends on shared state. Objects and behaviors are often grouped into the same entity and any number of functions are accessed randomly in an unspecified order, which can lead to unexpected behaviors such as race conditions.
Pros of functional programming:Functional models allow programmers to avoid race conditions and side effects, eliminating errors caused by multiple functions competing for the same resource. Features like non-dot type availability (also known as implicit programming) tend to greatly simplify functions and make it easier to recompile into more common reusable code than programming. Object-oriented program. Functional programming also tends to be declarative and declarative. They don't provide step-by-step instructions for the operation, but focus on what to do, so the underlying function needs to do which one. This gives you a lot of freedom in refactoring and performance tuning, allowing you to replace the entire algorithm with a more efficient algorithm with very little code change. (For example, save or use lazy evaluation instead of anxious evaluation.) Processing with pure functions is a multiple processor or distributed process without fear of facing challenges, resource conflicts, conflicts, and so on. It can easily be extended to a cluster. ..
Cons of functional programming:
5. When is classical inheritance an appropriate choice?
The answer is never or almost never. Certainly never more than one level. Multilevel class hierarchies are an anti-pattern.