Referential Transparency (computer Science) - Contrast To Imperative Programming

Contrast To Imperative Programming

If the substitution of an expression with its value is valid only at a certain point in the execution of the program, then the expression is not referentially transparent. The definition and ordering of these sequence points are the theoretical foundation of imperative programming, and part of the semantics of an imperative programming language.

However, because a referentially transparent expression can be evaluated at any time, it is not necessary to define sequence points nor any guarantee of the order of evaluation at all. Programming done without these considerations is called purely functional programming.

One advantage of writing code in a referentially transparent style is that given an intelligent compiler, static code analysis is easier and better code-improving transformations are possible automatically. For example, when programming in C, there will be a performance penalty for including a call to an expensive function inside a loop, even if the function call could be moved outside of the loop without changing the results of the program. The programmer would be forced to perform manual code motion of the call, possibly at the expense of source code readability. However, if the compiler is able to determine that the function call is referentially transparent, it can perform this transformation automatically.

The primary disadvantage of languages which enforce referential transparency is that it makes the expression of operations that naturally fit a sequence-of-steps imperative programming style more awkward and less concise. Such languages often incorporate mechanisms to make these tasks easier while retaining the purely functional quality of the language, such as definite clause grammars and monads.

With referential transparency, no difference is made or recognized between a reference to a thing and the corresponding thing itself. Without referential transparency, such difference can be easily made and utilized in programs.

Read more about this topic:  Referential Transparency (computer Science)

Famous quotes containing the words contrast to, contrast, imperative and/or programming:

    Unlike Boswell, whose Journals record a long and unrewarded search for a self, Johnson possessed a formidable one. His life in London—he arrived twenty-five years earlier than Boswell—turned out to be a long defense of the values of Augustan humanism against the pressures of other possibilities. In contrast to Boswell, Johnson possesses an identity not because he has gone in search of one, but because of his allegiance to a set of assumptions that he regards as objectively true.
    Jeffrey Hart (b. 1930)

    In contrast to revenge, which is the natural, automatic reaction to transgression and which, because of the irreversibility of the action process can be expected and even calculated, the act of forgiving can never be predicted; it is the only reaction that acts in an unexpected way and thus retains, though being a reaction, something of the original character of action.
    Hannah Arendt (1906–1975)

    If the Revolution has the right to destroy bridges and art monuments whenever necessary, it will stop still less from laying its hand on any tendency in art which, no matter how great its achievement in form, threatens to disintegrate the revolutionary environment or to arouse the internal forces of the Revolution, that is, the proletariat, the peasantry and the intelligentsia, to a hostile opposition to one another. Our standard is, clearly, political, imperative and intolerant.
    Leon Trotsky (1879–1940)

    If there is a price to pay for the privilege of spending the early years of child rearing in the driver’s seat, it is our reluctance, our inability, to tolerate being demoted to the backseat. Spurred by our success in programming our children during the preschool years, we may find it difficult to forgo in later states the level of control that once afforded us so much satisfaction.
    Melinda M. Marshall (20th century)