Hacker News new | past | comments | ask | show | jobs | submit login

It is actually a rather hard question. There is a web page somewhere where the author asks it, lists possible answers and get amazed by some of the definitions, such as "declarative is parallelizable". Cannot find it now, unfortunately.

I would say that imperative is the one that does computation in steps so that one can at each step decide what to do next. Declarative normally lacks this step-like quality. There are non-languages that consist solely of steps (e.g. macros in some tools that allow to record a sequence of steps), but while this is indeed imperative, this is not programming.




Here’s my personal attempt at a definition.

One side cares more about how the solution is implemented. They put a lot of focus on the stuff inside functions: this happens, then that happens, then the next thing happens.

The other side cares more about the outside of functions. The function declarations themselves. The types they invoke and how they relate to one another. The way data flows between parts of the program, and the constraints at each of those phases.

Obviously a program must contain both. Some languages only let you do so much in the type system and everything else needs to be done procedurally. Some languages let you encode so much into the structure of the program that by the time you go to write the implementations they’re trivial.


Sounds like a page worth another search if you don't mind. I'll give you Internet Points in return!

-- my attempt:

Imperative defines the order and semantics of each step.

Declarative defines the prerequisites and intent of each step.

The algorithms each can implement are equivalent.


Found it:

https://existentialtype.wordpress.com/2013/07/18/what-if-any...

Semantic is another word that is hard to define.


I read that and the followup. It’s good writing but I slightly disagree. Imperative is actually a closer mathematical formalism for some things.

I find imperative better for expressing state machines. I find declarative better for backtracking.

You can write a state machine with just a loop, an assignable, and conditions. Writing state in prolog is irritating.


You don't even need a loop. Steps, conditions, and a 'goto'. Loop are actually a design mistake. They try to bound 'goto' by making it structured. They are declarative, by the way. As a special case or even as a common case they are fine, but not when they try to completely banish 'goto'. They are strictly secondary.

Similarly declarative programming is strictly secondary to imperative. It is a limited form of imperative that codifies some good patterns and turns them into a structure. But it also makes it hard or impossible not to use these patterns.


(I would also say that state machine is a foundational model for programming.)




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: