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.
He's saying that a small, simple, imperative core is easy to understand (and the rest of the language is built on that), whereas more declarative languages tend to involve more complex compilers and more magic, making those languages harder to learn and comprehend.
Yes, for some unstated definition of "imperative" and "declarative".
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.
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 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...
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.
Yes because his use of the terms "imperative" and "declarative" are not the way I generally use them. When talking languages, I always thought you had imperative, functional, and declarative. Clojure is functional because of it's use of concepts like "functions are first order objects", closure, higher order functions, etc. I would never consider Clojure imperative.
EDIT: Possibly with the use of core.logic you could argue that it is "declarative" if you wanted to ;)
I would agree with that. Putting Clojure in the imperative camp seems a little skewed.
From the front page of clojure.org "Clojure is predominantly a functional programming language, and features a rich set of immutable, persistent data structures."
But I don't think that's his point as seancorfield pointed out.
That's not how I see it (but of course this largely depends on your definitions).
The main paradigms are imperative and declarative (think Assembler vs. Prolog if you want to go to the extremes).
'Functional' describes the language at a different level, as does 'object-oriented'.
If you go down to the core ideas, being functional is a declarative concept (mathematical functions are relations between sets), and object-oriented an imperative concept (objects are an abstraction over mutable state).
However, that's not necessarily how these concepts appear in practice (a function call is an instruction to trigger a compuation, the set of messages understood by an object declares its interface), and almost all programming languages are multi-paradigm anyway.
And, possibly, help the author sell a few books [1].
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.
(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)This also makes it much more impactful when you do use visual emphasis because its much clearer that its important.