ComputerScientist
174 subscribers
14 photos
3 files
206 links
▜ The Inventor

Stuff that inspire you to create.

See also: ▙ @LitMind
Download Telegram
#Programming_paradigms : Declarative versus Imperative

#Declarative
All about relations.

Does not state the order in which operations execute.

Focuses on what the program should accomplish without specifying how the program should achieve the result.
Expresses the logic of a computation without describing its control flow.

Common declarative languages include those of database query languages (e.g. #SQL, #XQuery), regular expressions (#Regex), logic programming, functional programming, and configuration management systems.

e.g. #Haskell, #Kanren (a dialect of #Scheme), #Prolog, #Wolfram_Language

#Imperative
Uses statements that change a program's state.
1. they state the order in which operations occur, with constructs that explicitly control that order

Allows side effects, in which state can be modified within one unit of code, and then read inside a different unit of code.

Imperative programming focuses on describing how a program operates.
an imperative program consists of commands for the computer to perform.
Many imperative programming languages (such as #Fortran, #BASIC, and #C) are abstractions of assembly language.
ComputerScientist
#Programming_paradigms : Declarative versus Imperative #Declarative All about relations. Does not state the order in which operations execute. Focuses on what the program should accomplish without specifying how the program should achieve the result. Expresses…
#Programming_paradigms
Expression versus Statement
An expression is a unit of #declarative programming.
A statement is a unit of #imperative programming.
An expression is evaluated whereas a statement is executed.

Expressions
A combination of values, variables and functions that return a value and have no side effects.

Expressions can contain functions and functions may have side effects. A side effect is a change to the abstract state of the running program that does not depend on the function input.

Functional programs do not have assignment statements therefore the value of a variable never changes once defined. An expression is said to be referentially transparent if it can be replaced with its corresponding value without changing the program's behavior. Evaluating a referentially transparent function gives the same value for same arguments. Such functions are called pure functions. Referentially transparent expressions allow #memoization.

Statements
Do not return results and are executed solely for their side effects.

Simple statements:
• assertion
• assignment
• goto
• return
• call

Compound statements: (may contain statements as components)
• block
• choice
• iteration