Declarative, Imperative in computer science

2020-07-11

In computer science, declarative programming is a programming paradigm—a style of building the structure and elements of computer programs—that expresses the logic of a computation without describing its control flow. This is in contrast with imperative programming, which implements algorithms in explicit steps.[1]

For example.

// Declarative
function getSharks(){
  var sharks = [];
  for (var i = 0; i < ...) {
    if(bla){
        sharks.add(...);
    }
  }
  return sharks;
}

// Imperative
Select * FROM animal WHERE sth='sharks';
Buy Me A Coffee