What is a paradigm?

Asked

Viewed 3,301 times

56

What is a paradigm?

Is there any more important than another?

It’s the same thing Pattern design (design pattern)?

It’s the same as language?

2 answers

44


What is a paradigm?

According to the Wikipedia:

Paradigm (from the late Latin paradigm, from the Greek παράδειγμα, derived from παραδείκνυμι «show, present, confront») is a concept of science and epistemology (the theory of knowledge) that defines a typical example or model of something. It is the representation of a pattern to be followed. It is a philosophical assumption, matrix, ie a theory, a knowledge that originates the study of a scientific field; a scientific realization with methods and values that are conceived as a model; an initial reference as a model basis for studies and research.

In more specific article on programming:

The notion of programming paradigms is a way of classifying programming languages according to the style of computer programming. Features of various programming languages determine which paradigms they belong to; as a result, some languages fall into only one paradigm, while others fall into several paradigms. Some paradigms are concerned primarily with implications for the language execution model, such as allowing side effects, or whether the sequence of operations is defined by the execution model. Other paradigms are concerned primarily with the way the code is organized, such as grouping code into units, along with the state that is modified by the code. However, others are primarily concerned with the style of syntax and grammar.

If you have to summarize in a sentence: it’s just a style of how to write a code. It’s the way the text (code) will be in general lines.

Some people prefer to speak in the paradigm more broadly and not only in the code, there is the style of the solution as a whole.

In general there are some "rules" that determine what may or may not be in the code indicating whether it is of one paradigm or another. Some things are forbidden, some are mandatory.

Of course the rule is free, but I see some people catching one subset of the rules of the paradigm and to say that something was written according to that paradigm. It is probably a mistake. Even because some paradigms are subsets of others, then you give a name to one thing when it’s actually another.

It is common for people to want their code to be of the fashion paradigm, even if it does not pass near that.

Is there any more important than another?

You can’t say that. There are some more popular (technically or by marketing).

Some people consider that there are only three or four paradigms. They determine this through a vector with two characteristics that the code can have.

"But I saw a huge list in the Wikipedia article". Yes, there are several other secondary ones that can be combined with these main ones. But do not lose sight that they are secondary, even if some of them are more famous. Fame has nothing to do with effective use. Some consider it an abuse to call them paradigm.

Languages can execute or evaluate, focus on the mechanism or the consequence.

  • When executes and focuses on mechanism you have the paradigm imperative. It is fired the most used, for good or ill its use is overwhelming. In practice most programmers have never experienced anything out of it. The vast majority of languages are based on it. All strongly mainstream.

  • When evaluates and focuses on mechanism you have the paradigm functional. It has an expressive niche that uses it, but that’s it (at least in its pure form, although they say that there is no truly functional viable language). It is very common to take parts of it to complement the imperative. Lisp, ML, Haskell, are examples.

  • When evaluates and focuses on consequence you have the paradigm logical. Its use is extremely restricted and the vast majority of programmers have never seen a code on it. The rise of artificial intelligence could slightly increase its use, but it is not happening. Prolog is the most classical language.

  • When executes and focuses on consequence you have the paradigm of goals. In practice it is not used anywhere, so some disregard it.

Paradigmas

Other paradigms basically cannot exist without them being at the bottom. So the others are orthogonal and these are not among them (although some elements can be mixed, but not the whole paradigm).

Some say that there is only the imperative and the declarative. I can accept this definition.

There is a definition that language can only have one paradigm, the rest are Features extras. It makes sense. And then it is better to define only the main ones, if trying to define all possible combinations becomes crazy.

OOP

"But I hear so much of object orientation, isn’t it important?". No. It’s useful. For some problems, it’s a highly desirable choice. Other times a similar paradigm, or a combination of other paradigms, is more appropriate.

Even in so-called purely object-oriented languages (I’m talking about Smalltalk, nor of Java, Ruby and things like that it is laughable to use the words "OO" and "pure" together with their names) in the background the basic paradigm is imperative with strong influence of object orientation. It is true that the imperative tries to be hidden, but it is still there.

Its importance is more in people’s heads (although most people do not understand what the paradigm means and how to use it, because there are controversies about what it is in fact) than in the ability to define something useful for the code. It is useful at very specific points. At the risk of the answer getting dated, it is the Trump of the programming. Everyone speaks of it, few understand it. Many support it, few need it most of the time. It is useful, but not for protagonism.

If you are of those who consider the secondary ones not even paradigms, then OO is not a paradigm :P

Secondary paradigms

Some pass scraping as paradigm. If you think it’s only paradigm if you can exist independently then maybe none of these are paradigms at all.

Most of them refer to the organization of the code (in general to data structures) or to a specific mechanism, so it can only be applied in part of the code. Therefore, the expression "oriented to".

I’ve spoken of the most famous.

Meta programming is used in some languages and tends to be used more and more to give flexibility and expressiveness to the code, when the problems are increasingly complex and find good solutions. One part of this is reflection. The programming generic is another that is a subset of this. Already the language orientation is probably a superset.

An important mechanism is the event. Another, in some problems, is the agent.

Another very interesting mechanism gaining a little popularity is the aspect-oriented.

It is common to have specific points to facilitate the parallelism and the competition.

More and more is used the contract. Not everyone considers a paradigm, but if it’s not, most secondary ones are not.

Some languages adopt some very specific mechanism. Even the paradigm genetic exists.

People should know more about the paradigm modular (more information). In some ways it’s a superset oop.

Anyway, just to name a few.

Some believe that there are no paradigms. I disagree.

Diagram showing the main paradigms:

Paradigmas de programação

It’s the same thing Pattern design?

It is not the same thing. A design pattern is something more specific, solves something more contained and has a more concrete example of how to implement a solution to the problem. More like a jig.

Often a design pattern is implemented in the language transparently, helping to achieve a goal of a paradigm.

If the solution involves a level above abstraction of the problem it will probably be called architecture standard.

It’s the same as language?

They are more specific techniques, usually within a paradigm. It is common to apply only to a specific language. Let’s say it stands in the middle between the design pattern and the paradigm.

  • 6

    Fantastic answer. :)

  • What kind of paradigm would Assembly fit into?

  • 1

    @Denercarvalho good question, I would say it is imperative pure, but someone could deny me :)

  • 1

    @bigown "Script" can be considered a programming paradigm?

  • 1

    Another good question :) I don’t think so, but it could be depending on how you analyze it. To validate this would require someone to write something convincing showing why it is a paradigm. These things always depend on someone saying they are, with property. Note that in the answer I do not talk much about being or not, says what some people think. There are those who disagree. These things are complicated.

  • 1

    "To validate this one would need to write something convincing showing why it is a paradigm." = > Do Houaiss: Paradigma. 1. um exemplo que serve como modelo; padrão. 2. conjunto de formas vocabulares que servem de modelo para um sistema de flexão ou de derivação (p.ex.: na declinação, na conjugação etc.); padrão. Scripts have fundamental features (i.e. errors only at runtime, absence - in principle - of compilation, etc) and ideal conditions of use (i.e. ease of change) that arguably make the concept into a kind of model to be followed. Therefore, a paradigm. :)

  • 2

    @Luizvieira I agree with everything, I just didn’t see anything more formal saying it. I reaffirm, I do not think you are wrong, quite the contrary, even, but it is just a person saying in a comment of Sopt :P You convinced me, I need to convince the rest. Put it on Wikipedia and wait for firewood :) It doesn’t have the same weight as an academic scrutiny, but it’s something.

  • 1

    You’re absolutely right. And I’m really no one to try to convince others (even you). The intention was even just to exercise my argument and try the answer (after all, it sounded a bit like a challenge to my nerd level... rs)

Show 3 more comments

17

What is a paradigm?

In programming, a graph is a way of thinking about problems and developing solutions. It is said that a given programming language supports a given paradigm.

When solving a problem, the programmer develops a mental model of it. The set of concepts he uses to understand the problem and structure his solution is what we call the paradigm.

For example, if it adopts the object orientation paradigm, it will think of the problem as a set of objects that have state in the form of variables and expose behavior through methods. However, if instead he employs the functional paradigm, he will adopt a more mathematical model, modeling the problem as a series of functions that can be composed.

Similarly: if he prefers to tell the computer exactly what to do, then he is thinking imperatively. If it is better to specify the facts about the problem to be solved and let the computer work without specifying how, then it is solving the problem declaratively.

These paradigms materialize when coding the solution of the problem in a programming language. It is then that the differences between them become more evident, even among those who support the same paradigm.

Java is a classic example of language that supports object orientation, but there are languages like Smalltalk that take this paradigm to places that Java just can’t get to. It is possible to use object orientation in C, but at great cost: what in Java is implicit in the language itself, as inheritance between classes, has to be explicitly encoded in C.

It is possible to select data in a database in an imperative way. In fact, the database operates in this way. Even so it is more practical to simply say what data you want using SQL and let it figure out what it has to do alone. From time to time, software does this inefficiently and it becomes a problem; this is the time to think in an imperative way, because consider as the database is running the query will allow to discover the cause of inefficiency.

Is there any more important than another?

In isolation, it is difficult to say objectively. Each of them had a unique impact on the way programmers think. It is said that it is not worth learning a programming language that does not change the way you think about the problems you solve.

When the question is asked along with a description of the problem to which the paradigm will be applied, the question becomes clearer.

It’s the same thing Pattern design?

Design patterns are architectural patterns, ways of organizing language elements to generate specific effects such as "ensuring that only a single instance of a class exists".

A different paradigm can make these patterns unnecessary by offering alternative ways to solve the problem that do not present the flaws that the design pattern attempts to mitigate.

It’s the same as language?

Languages exist in the context of a programming language. They refer to recurring patterns of language use by programmers.

It can be said that idiomatic code is one that exploits language to the fullest, and so is clearer and more succinct than a supposed non-indigenous code.

For example, in Ruby, the following code is idiomatic:

[1, 2, 3, 4, 5].select &:even?

Is equivalent to the following code:

[1, 2, 3, 4, 5].select { |n| n.even? }

The first example is generally preferred among experienced Ruby programmers for dispensing with the use of keys and variable n.

To understand nonidiomatic code, it is enough to understand objects, methods and blocks; simple and basic parts of the Ruby language. Idiomatic code requires much more programmer knowledge:

  • Meaning of the operator & and its relationship with the blocks
  • Method to_proc
    • Language protocol for turning objects into blocks
  • Symbols
    • Symbol#to_proc and its operation

Endowed with this knowledge, a Ruby programmer may discover that it is possible to combine the unary operator & with a symbol. The & converts using to_proc and passes its argument as a block in the call of a method, while a symbol can be implicitly converted to a block in the pattern :sym => proc { |x| x.sym }. A language is born.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.