четверг, 16 января 2020 г.

DECLARATICE vs IMPERATIVE PROGRAMMING


Imperative programming – is a programming paradigm that focuses on how to execute, defines control flow as statements that change a program state. How to do?
C++ /Powershell / Java / Groovy / Python

Declarative programming – is a programming paradigm that focuses on what to execute, defines program logic, but not detailed control flow. What to do?
SQL/Prolog/

Python Example
# Declarative
small_nums = [x for x in range(20) if x < 5]
# Imperative
small_nums = []
for i in range(20):
    if i < 5:
        small_nums.append(i)

Комментариев нет: