Big Chemical Encyclopedia

Chemical substances, components, reactions, process design ...

Articles Figures Tables About

Imperative versus Declarative Programming

A code example of an imperative language (C-h-) is shown following. This is a function that normalizes a vector according to the Euclidian L -Norm — that is, it divides each component of a vector by the square root of the sum of products of all vector components. [Pg.37]

The function is called with two parameters, one of which is a pointer ( ) to a multidimensional variable (Vector) that represents the input vector that has to be normalized. The other parameter is the length of the vector (N). The code then declares a variable (Norm) and initializes it, or (assigns a start value of zero). It then defines a loop (for statement) that runs over all components (i) of the vector to summarize all component products. It then calculates the square root (sqrt) of the sum. In a second loop, it again runs over all vector components to divide them by the square [Pg.37]

Descriptive Languages Macro Languages, VBA JavaScript, VB, Python, Perl C+ t, C, Java, Python, Perl FORTRAN, Common LLSP, C Assembler [Pg.38]

This is a procedural algorithm that is performed in a sequential manner and leads to an explicit answer. The program code may be called from another code and may include function calls, such as the square root function sqrt. [Pg.39]

Closely related to the latter is declarative programming that describes states rather than how to achieve them. Additionally, the syntax is modeled after the way humans describe a state and thus is more declarative than other languages. [Pg.39]


See other pages where Imperative versus Declarative Programming is mentioned: [Pg.37]    [Pg.37]   


SEARCH



Declaration

Imperatives

© 2024 chempedia.info