Usuari:U1926643/proves

De Viquipèdia
Salta a la navegació Salta a la cerca

Programming paradigm[modifica]

programming paradigm is a fundamental style of computer programming, serving as a way of building the structure and elements of computer programs. Capabilities and styles of various programming languages are defined by their supported programmingparadigms; some programming languages are designed to follow only one paradigm, while others support multiple paradigms.

Programming paradigms that are often distinguished include imperative, declarative, functional, object-oriented, procedural, logicand symbolic programming.[1][2][3] With different paradigms, programs can be seen and built in different ways; for example, in object-oriented programming, a program is a collection of objects interacting in explicitly defined ways, while in declarative programming the computer is told only what the problem is, not how to actually solve it.

Overview[modifica]

Overview of the various programming paradigms according to Peter Van Roy[4]:5

Just as software engineering (as a process) is defined by differing methodologies, so theprogramming languages (as models of computation) are defined by differing paradigms. Some languages are designed to support one particular paradigm (Smalltalk supports object-oriented programming, Haskell supports functional programming), while other programming languages support multiple paradigms (such as Object Pascal, C++, Java,C#, Scala, Visual Basic, Common Lisp, Scheme, Perl, Python, Ruby, Oz and F#). For example, programs written in C++ or Object Pascal can be purely procedural, purelyobject-oriented, or they can contain elements of both or other paradigms. Software designers and programmers decide how to use those paradigm elements.

In object-oriented programming, programmers can think of a program as a collection of interacting objects, while in functional programming a program can be thought of as a sequence of stateless function evaluations. When programming computers or systems with many processors, process-oriented programming allows programmers to think about applications as sets of concurrent processes acting upon logically shared data structures.

Many programming paradigms are as well known for what techniques they forbid as for what they enable. For instance, pure functional programming disallows the use of side-effects, while structured programming disallows the use of the goto statement. Partly for this reason, new paradigms are often regarded as doctrinaire or overly rigid by those accustomed to earlier styles.[5]Avoiding certain techniques can, though, make it easier to prove theorems about the correctness of a program, or simply to understand its behavior.

Programming paradigms can also be compared with programming models that are abstractions of computer systems. For example, the "von Neumann model" is a programming model used in traditional sequential computers. For parallel computing, there are many possible models typically reflecting different ways processors can be interconnected. The most common are based on shared memory, distributed memory with message passing, or a hybrid of the two.

Some programming language researchers criticise the notion of paradigms as a classification of programming languages, e.g. Krishnamurthi.[6] They argue that many programming languages cannot be strictly classified into one paradigm, but rather include features from several paradigms.

Història[modifica]

Amb el temps s'han desenvolupat diferents disciplines de programació, sent identificades al moment o retrospectivament. Una de les primeres disciplines identificada com a tal va ser la programació estructurada, proposada des de mitjans dels anys 1960s. El concepte de "paradigma de programació" com a tal data al menys del 1978, en la conferència del Premi Turing de Robert W. Floyd, titulada The Paradigms of Programming (Els Paradigmes de Programació), que cita la idea de paradigma de programació usada per Thomas Kuhn al seu llibre L'estructura de les revolucions científiques (The Structure of Scientific Revolutions) de 1962.

Codi màquina[modifica]

El nivell més baix dels paradigmes de programació és el codi màquina, que representa directament les instruccions (els continguts de la memòria del programa) com una seqüencia de números, i el llenguatge d'assemblador on les instruccions són representades per mnemònics i adreces de memòria.

En els anys 1960s, els llenguatges d'assemblador van ser desenvolupats per suportar la llibreria COPY, CALL a subrutines, variables externes i seccions comunes (globals), permetent reutilització de codi i aïllament del hardware fent servir operadors lògics com READ, WRITE, GET i PUT.

Llenguatges procedurals[modifica]

El següent avanç va ser el desenvolupament de llenguatges procedurals. Aquests llenguatges fan servir vocabulari relacionat amb el problema a resoldre. Per exemple:

  • COBOL (COmmon Business Oriente Language) - fa servir termes com file, move i copy.
  • FORTRAN (FORmula TRANslation) - fa servir terminologia del llenguatge matemàtic.
  • ALGOL (ALGOritmic Language) - enfocat a ser un llenguatge apropiat per definir algoritmes, també fent servir llenguatge matemàtic.
  • PL/I (Programing Language One) - un híbrid comercial/científic de propòsit general amb suport per a punters.
  • BASIC (Begginers All purpose Symbolic Instruction Code) - va ser desenvolupat per permetre escriure programes a més persones.
  • C - un llenguatge de propòsit general.

Tots aquests llenguatges segueixen un paradigma procedural. Descriuen, pas a pas, exactament el procés que ha de ser seguit per resoldre un problema específic. La eficàcia i eficiència de cada solució depenen en l'experiència, la inventiva i l'habilitat del programador.

Programació orientada a objectes[modifica]

Despès de l'estès ús dels llenguatges procedurals, es van crear els llenguatges orientats a objectes com Simula, Smalltalk, C++, C#, Eiffel i Java. En aquests llenguatges, les dades i els mètodes per manipular-la es mantenen com una sola unitat anomenada objecte. La única manera en que un usuari pot accedir les dades és a través dels "mètodes" de l'objecte, com a conseqüència, el funcionament intern d'un objecte pot ser modificat sense afectar cap codi que fa servir l'objecte. Encara hi ha controvèrsia plantejada per Alexander StepanovRichard Stallman i altres programadors, sobre l'eficàcia del paradigma POO en comparació del paradigma procedural. La necessitat de cada objecte de tenir mètodes associatius porta a alguns escèptics a associar POO amb software inflat. El polimorfisme va ser desenvolupat com un intent per resoldre aquest dilema.

Com que la programació orientada a objectes és considerada un paradigma, i no un llenguatge, és possible fins i tot crear un llenguatge d'assemblador orientat a objectes. L'assemblador d'Alt Nivell (High Level Assembly) és un exemple d'això, que suporta completament els tipus de dades avançats.

Further paradigms[modifica]

Literate programming, as a form of imperative programming, structures programs as a human-centered web, as in a hypertext essay: documentation is integral to the program, and the program is structured following the logic of prose exposition, rather than compiler convenience.

Independent of the imperative branch, declarative programming paradigms were developed. In these languages the computer is told what the problem is, not how to solve the problem – the program is structured as a collection of properties to find in the expected result, not as a procedure to follow. Given a database or a set of rules, the computer tries to find a solution matching all the desired properties. The archetypical example of a declarative language is the fourth generation language SQL, as well as the family of functional languages and logic programming.

Functional programming is a subset of declarative programming. Programs written using this paradigm use functions, blocks of code intended to behave like mathematical functions. Functional languages discourage changes in the value of variables through assignment, making a great deal of use of recursion instead.

The logic programming paradigm views computation as automated reasoning over a corpus of knowledge. Facts about the problem domain are expressed as logic formulae, and programs are executed by applying inference rules over them until an answer to the problem is found, or the collection of formulae is proved inconsistent.

Symbolic programming is a paradigm that describes programs able to manipulate formulas and program components as data.[3] Programs can thus effectively modify themselves, and appear to "learn", making them suited for applications such as artificial intelligence, expert systems, natural language processing and computer games. Languages that support this paradigm include LISP and Prolog.[9]

Multi-paradigm[modifica]

See also: Comparison of multi-paradigm programming languages

A multi-paradigm programming language is a programming language that supports more than one programming paradigm.[10] The design goal of such languages is to allow programmers to use the most suitable programming style and associated language constructs for a particular job, considering that no single paradigm solves all problems in the easiest or most efficient way.

One example is C#, which includes imperative and object-oriented paradigms as well as some support for functional programming with features like delegates (allowing functions to be treated as first-order objects), type inference, anonymous functions and Language Integrated Query. Other examples are F# and Scala, which provides similar functionality to C# but also includes full support for functional programming (including currying, pattern matching, algebraic data types, lazy evaluation, tail recursion, immutability, etc.). Perhaps the most extreme example is Oz, which has subsets that adhere to logic (Oz descends from logic programming), functional, object-oriented, dataflow concurrent, and other paradigms. Oz was designed over a ten-year period to combine in a harmonious way concepts that are traditionally associated with different programming paradigms. Lisp

Referències[modifica]

  1. Nørmark, Kurt. Overview of the four main programming paradigms.
  2. Frans Coenen (1999-10-11). "Characteristics of declarative programming languages".
  3. Michael A. Covington (2010-08-23). "CSCI/ARTI 4540/6540: First Lecture on Symbolic Programming and LISP" (PDF).
  4. Peter Van Roy (2009-05-12). "Programming Paradigms for Dummies: What Every Programmer Should Know" (PDF).
  5. Frank Rubin (March 1987). "'GOTO Considered Harmful' Considered Harmful" (PDF).
  6. Krishnamurthi, Shriram (November 2008). "Teaching programming languages in a post-linnaean age".
  7. Floyd, R. W. (1979). "The paradigms of programming".