Continuing with the previous post , the following classification of programming languages is by paradigms. If you want to see the whole thread of this post, here I leave the table of contents:
A programming paradigm is a methodology or programming philosophy to follow with a central core unquestionable, that is, the languages that use the same programming paradigm will use the same basic concepts to program.
|Imperative : Programmer indicates how to obtain the desired result.|
|Declarative: Programmer indicates what he wants to obtain the desired result.|
Within this group are different programming methodologies. Among them, the structured methodology and the object-oriented methodology.
At the end of the 70s, this methodology was born which allowed 3 types of structures in the code:
- Alternative (based on a decision).
- Repetitive (loops).
The structured program theorem states that each computable function can be implemented by combining structures sequentials, alternatives or repetitives.
Using these structures, encodings like the one in the image on the left can be replaced with a structured code like the one in the figure on the right:
The structured methodology evolved by adding the module as a basic component giving rise to structured and modular programming.
The programs were made up of modules or processes on the one hand and data on the other. The modules needed input data to get output data which in turn could beused by other modules. Example: C.
Module: independent code that performs a specific task.
With this evolution of structured programming methodology, it was possible to divide the problem into several subproblems that they can be solved separately and by joining them they get a final result.
- It is desirable that the modules have high cohesion and low coupling.
- Cohesion: measures the strength of the relationship between instructions for a given module.
- Coupling: is the level of independence there is between modules. Low coupling is normally a sign of a well-structured system and good software design.
Object: Abstraction of real life objects, both physical and abstract. All these objects have a state and a behavior. Each object is an instance of a class.
- Reals: car, house, bed, animal, person...
- Abstracts: a notification, a search ...
Class: A class is a plane or mold from which individual objects are created.
Programs contain objects that relate to or collaborate with other objects of the same class or from other classes. The class is made up of attributes (data) and methods (processes).
The most fundamental concepts within this methodology are:
- Encapsulation: Hide internal details of a class. Keywords within this concept are: Private, public, protected ...
- Inheritance: subclasses can be declared that inherit the properties and methods of the parent class.
- Polymorphism refers to the property by which it is possible to send syntactically equal messages to objects of different types. The only requirement that must be met by objects that are used in a polymorphic way is to know how to respond to the message sent to them. Let's try to give an example of this: all animals make a sound, but this sound is different depending on the type of animal that emits it. Everyone will inherit the emitSound method from the parent class, but each subclass will do it differently. Let's see it graphically.
The world of object-oriented programming is big, in another post, I will continue to cover this topic. For now, let's continue with our classifications.
The form of coding in this paradgim contains a set of conditions, propositions, affirmations, constraints, equations, or transformations that describe the problem and detail its solution. The programmer has to think about the logic of the algorithm and not in the sequencies of steps to perform. There are also different groups within this paradigm.
- Logic programming
- Algebraic programming
- Functional programming
This methodology emerged as a simple form of communication between humans and machines, unlike low-level languages, making use of mathematical logic, which is the simplest way for the human intellect to express and formally prove complex problems. The language by excellence within this methodology is Prolog.
Methodology used mostly in relational database query languages such as SQL or Maude. This language makes use of a collection of relational schema operations that is used to manipulate relationships. The result of an operation, in turn, is also a relation, which allows you to chain calculations by applying an operator to the result of a previous calculation. These operators are the ones used by relational algebra:
This is an example of using relational algebra with the unary SELECTION primitive operator in SQL.
There are concepts within this methodology:
First-class and higher-order functions: they are functions that can take other functions as arguments or return them as results.
Pure functions: have not side effects (memory or I / O). They are widely used in code optimization
Strict(eager) vs. Non-Strict(Lazy) evaluation: concepts that refer to how function arguments are processed when an expression is being evaluated.
Type systems: The use of algebraic data types and pattern matching makes manipulation of complex data structures convenient and expressive, the presence of strict type checks at compile time makes programs more reliable, while type inference relieves the programmer of the need to manually declare the types for the compiler.
We have learned a lot today about paradigm classification of some languages. In the next post we will continue with the last classification ways. See you soon.