Imperative and declarative programming in simple language – experts explain

Declarative programming is a programming paradigm in which the specification of the solution to a problem is specified: it describes what the problem is and the expected result, but without describing the way to achieve this result. Often, declarative programs do not use the concept of state and, in particular, do not contain variables and assignment operators, providing referential transparency. Functional programming is often referred to as a subtype of declarative programming. Declarative computer languages ​​are often not Turing complete, since theoretically it is not always possible to generate executable code from a declarative description.

Imperative programming is a programming paradigm in which the sequence of actions required to produce a result is specified. It uses variables, assignment operators, and compound expressions.

Despite the fact that the declarative approach to programming was historically the first to be applied, the first computer programming languages ​​(machine, assembler, Fortran, Algol, Cobol) were imperative due to the simplicity of the approach.

Both highly specialized declarative programming languages ​​(HTML + CSS, SVG, VRML, SQL, lex / VACC), including functional (Haskell, Erlang, Scala) and imperative languages ​​(C / C ++ / C #, Java, Go , Rust, Python). However, almost all modern high-level general-purpose programming languages, with the exception of some functional ones, are imperative languages.

The choice of a particular programming paradigm – imperative or functional – is mainly determined by the requirements for the program and a set of advantages and disadvantages of each of the paradigms. For example, the independence of functions by data in functional languages ​​and the absence of side effects greatly reduces the number of errors and allows you to effectively parallelize the code. Therefore, to create highly loaded systems with a high level of parallel computing, it is more reasonable to choose one of the functional languages.

On the other hand, the immutability of input data in functional programming languages ​​makes it difficult to create systems that actively perform input-output and modification of existing data. To implement such systems, it is preferable to choose imperative languages.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *