
Imperative programming The term is used in opposition to declarative programming, which expresses what the program should accomplish without prescribing how to do it in terms of sequences of actions to be taken. Functional and logic programming are examples of a more declarative approach. Imperative, procedural, and declarative programming[edit] Procedural programming could be considered a step towards declarative programming. A programmer can often tell, simply by looking at the names, arguments and return types of procedures (and related comments), what a particular procedure is supposed to do, without necessarily looking at the details of how it achieves its result. At the same time, a complete program is still imperative since it 'fixes' the statements to be executed and their order of execution to a large extent. Declarative programming is a non-imperative style of programming in which programs describe their desired results without explicitly listing commands or steps that must be performed. History[edit]
specs2 @ GitHub Specify your software using both text and Scala code class HelloWorldSpec extends Specification { def is = s2""" This is a specification for the 'Hello world' string The 'Hello world' string should contain 11 characters $e1 start with 'Hello' $e2 end with 'world' $e3 """ def e1 = "Hello world" must haveSize(11) def e2 = "Hello world" must startWith("Hello") def e3 = "Hello world" must endWith("world") } Use different styles of specifications /** This is the "Unit" style for specifications */class HelloWorldSpec extends Specification { "This is a specification for the 'Hello world' string".txt "The 'Hello world' string should" >> { "contain 11 characters" >> { "Hello world" must haveSize(11) } "start with 'Hello'" >> { "Hello world" must startWith("Hello") } "end with 'world'" >> { "Hello world" must endWith("world") } }} Document your APIs with compiler-checked examples Manage contexts for integration testing
Programmation fonctionnelle Un article de Wikipédia, l'encyclopédie libre. Machine à états et effets secondaires[modifier | modifier le code] Programmation impérative et effets de bord[modifier | modifier le code] La programmation impérative s'appuie sur le modèle des machines à états (cf. aussi machine de Turing et Architecture de von Neumann), avec une mémoire centrale et des instructions qui modifient son état grâce à des affectations successives. On peut représenter un tel programme par une machine à états qui représente les états successifs de la mémoire. Cela nécessite pour le programmeur de connaître à tout instant un modèle exact de l'état de la mémoire que le programme modifie. Programmation fonctionnelle[modifier | modifier le code] La programmation fonctionnelle s'affranchit de façon radicale des effets secondaires (ou effets de bord) en interdisant toute opération d'affectation. Transparence référentielle[modifier | modifier le code] Des fonctions passées en paramètre[modifier | modifier le code]
Object-oriented programming Overview[edit] Rather than structure programs as code and data, an object-oriented system integrates the two using the concept of an "object". An object has state (data) and behavior (code). Objects correspond to things found in the real world. So for example, a graphics program will have objects such as circle, square, menu. The goals of object-oriented programming are: Increased understanding.Ease of maintenance.Ease of evolution. The overall understanding of the system is increased because the semantic gap—the distance between the language spoken by developers and that spoken by users—is lessened. Object-orientation takes this to the next step. In addition to providing ease of maintenance, encapsulation and information hiding provide ease of evolution as well. An object-oriented program usually contains different types of objects, each corresponding to a real-world object or concept such as a bank account, a hockey player, or a bulldozer. History[edit] A survey by Deborah J.
Scala Closure (computer programming) def start(x): def increment(y): return x+y return increment The closures returned by start can be assigned to variables like first_inc and second_inc. Invoking increment through the closures returns the results below: first_inc = start(0) second_inc = start(8) first_inc(3) # returns 3 second_inc(3) # returns 11 # The x value remains the same for new calls to the function: first_inc(1) # returns 1 second_inc(2) # returns 10 In ML, local variables are allocated on a linear stack[citation needed]. Closures are closely related to Actors in the Actor model of concurrent computation where the values in the function's lexical environment are called acquaintances. Closures are closely related to function objects; the transformation from the former to the latter is known as defunctionalization or lambda lifting. ; Return a list of all books with at least THRESHOLD copies sold. Here is the same example rewritten in JavaScript, another popular language with support for closures:
Syntax (programming languages) In computer science, the syntax of a computer language is the set of rules that defines the combinations of symbols that are considered to be a correctly structured document or fragment in that language. This applies both to programming languages, where the document represents source code, and markup languages, where the document represents data. The syntax of a language defines its surface form.[1] Text-based computer languages are based on sequences of characters, while visual programming languages are based on the spatial layout and connections between symbols (which may be textual or graphical). Documents that are syntactically invalid are said to have a syntax error. Computer language syntax is generally distinguished into three levels: Words – the lexical level, determining how characters form tokens;Phrases – the grammar level, narrowly speaking, determining how tokens form phrases;Context – determining what objects or variables names refer to, if types are valid, etc. 'a' + 1 a + b
Spring Source Logic programming Logic programming is a programming paradigm based on formal logic. Programs written in a logical programming language are sets of logical sentences, expressing facts and rules about some problem domain. Together with an inference algorithm, they form a program. Major logic programming languages include Prolog and Datalog. A form of logical sentences commonly found in logic programming, but not exclusively, is the Horn clause. p(X, Y) if q(X) and r(Y) Logical sentences can be understood purely declaratively. The programmer can use the declarative reading of logic programs to verify their correctness. History[edit] The use of mathematical logic to represent and execute computer programs is also a feature of the lambda calculus, developed by Alonzo Church in the 1930s. In 1997, the Association of Logic Programming bestowed to fifteen recognized researchers in logic programming the title Founders of Logic Programming to recognize them as pioneers in the field:[1] Prolog[edit] H :- B1, …, Bn.