
Clojure is imperative as opposed to declarative - dgellow
http://www.lispcast.com/clojure-is-imperative
======
groovy2shoes
It's useless to categorize things as imperative or declarative without
defining those words. There aren't any agreed-upon definitions for what it
means to be imperative or declarative (or functional or object-oriented...).

At this point it's mostly an "I know it when I see it" kind of thing,
sometimes accompanied by a nebulous explanation about _what_ versus _how_.
There _is_ a difference that programmers can _feel_ , but we find it very hard
to communicate that difference. Even at that, virtually every language has
some aspects that are imperative and some that are declarative.

Without definitions (preferably rigorous ones), the only thing a post like
this will accomplish is starting a flame war.

~~~
lynndylanhurley
This is what I gathered from the context of the article:

Clojure is imperative in the sense that the code is evaluated and executed
sequentially. For example, a function cannot be referenced before it is
defined.

This is in contrast with (declarative) languages such as Haskell, in which the
compiler will evaluate the entire file before executing any code.

Someone please correct me if I'm mistaken.

~~~
ericn
That's close to what I meant.

Closer would be:

Clojure def is imperative because the semantics are defined mechanically,
leaving fewer implementation details up to the implementer.
[http://clojure.org/special_forms#Special](http://clojure.org/special_forms#Special)
Forms--(def symbol init?)

Haskell toplevel function definitions are more declarative because the
semantics are defined less concretely.
[https://www.haskell.org/ghc/docs/latest/html/users_guide/inf...](https://www.haskell.org/ghc/docs/latest/html/users_guide/informal-
semantics.html)

This is what I meant. I did not mean to start a flame war about the definition
of declarative. It's more about different approaches to language design.

------
dkersten
Almost all programming languages are imperative. However, you can often
program in a _declarative style_ and some languages lend themselves better to
this than others (either for technical or culture reasons).

Clojure is, at its core, imperative. Functional programming is not, IMHO, in
itself declarative. To me, functional is just an approach to imperative
programming.

Something like prolog is declarative: you tell it some rules and relationships
(constraints on your data) and let it find the data which matches this. You
declare the rules, it gives you the results. That's declarative:
relationships, constraints, rules - not steps (functional, procedural or
otherwise).

Clojure does lend itself quite well to declarative programming though.
Partially because of its features (macros/metaprogramming, functional
programming and immutability makes it easier too) and partially because of the
community culture (emphasis on the data etc) and this can be seen in the
libraries that have emerged in the ecosystem: core.logic is essentially
_embedded prolog_ , core.match lets you extract data declaratively, various
datalog-esque libraries (eg Dataomic) to query data declaritively and others
that I'm forgetting.

So in summary: I agree that Clojure isn't in itself declarative, but it is
quite well suited to programming in a declarative _style_.

------
elwell
I try to use function names that carry a 'declarative mindset' when I write
Clojure. E.g.,

    
    
      (sections x)
      instead of
      (get-sections x)
      
      (refactored (styled (second-half divs)))
      instead of
      (refactor (apply-styles (take-second-half divs)))
    

~ evoking a feeling that _defn_ is merely a parameterized form of _def_ (which
it truly is)

------
xiaoma
About 1/4 to 1/3 of this piece is emphasized, either via italicization or
bolding. Not only does that destroy the attention-getting nature that
emphasized text usually had, but it made it hard to get through the text.

~~~
dkersten
I've commonly heard it said (and I agree, although I used to make the mistake
myself in the past) that over-reliance on visual emphasis is a sign of bad
writing. Good writers use words, phrases, sentences, grammar and other
linguistic constructs for emphasis so don't need to rely on visual emphasis.

This also makes it much more impactful when you _do_ use visual emphasis
because its much clearer that its important.

------
sitkack
Isn't this a side effect of how the compiler is implemented?

