4

I've been teaching myself a bit about declarative vs imperative programming, and I've come to the (possibly false) understanding that declarative programming is more or less just abstraction.

For example, according to how I understand these concepts, calling a method to do something would be declarative, whereas the implementation of the method is imperative (not necessarily, though? Just not declarative).

Therefore, it seems as if wherever you have declarative code, somewhere down the line it must rely on non-declarative code for implementation. Is this just the nature of it, or are there languages that are 100% declarative (something I can't even begin to conceptualize)?

Please correct me if my understanding of these concepts is off! Although I'm roughly halfway through a B.A. in Computer Science, I feel like I've only been taught so far to "type stuff so that the right stuff happens when you run the code."

Thanks.

jah
  • 155
  • 1
  • 2
  • 11
  • 4
    I'm not an expert on this, but it seems like your question might be better suited for http://programmers.stackexchange.com/ which is more about concepts than solutions. You might also want to try Quora (http://www.quora.com/). – Rob Rose Jul 24 '15 at 17:13
  • Declarative code needs some sort of execution strategy. On common computer architectures at the moment that will rely on some sort of imperative programing in the implementation at some point. – shuttle87 Jul 24 '15 at 17:15
  • 2
    Part of this is due to the fact that this is true for any level of higher language organization. Everything ultimately compiles down to something in the processor instruction set, and at that level there is only imperative. You don't have enough kit to do functional, declarative, or anything else. In that sense, it is trivially true that declarative, functional, and lots of other higher-level language organizations "somewhere down the line must rely on [a] non-declarative [] implementation." – Two-Bit Alchemist Jul 24 '15 at 18:11

1 Answers1

0

Declarative programming expresses the logic of a software component without outlining it's control flow. That methodology of calling functions (which is called functional programming - a sub-paradigm of declarative programming) you are talking about can be a bit confusing, especially when learning programming and probably learning a language like C/C++/Java. There are functional programming languages, such as Lisp and Haskell, that utilize the functional paradigm completely.

When just starting off, I wouldn't try to learn the implementations of those paradigms simultaneously. Instead I find it easiest to think of declarative languages as the highly expressive languages like CSS SQL. They describe WHAT should be done in plain English with the HOW abstracted away.

taylorcressy
  • 966
  • 8
  • 23
  • Yeah, I started out with Scheme (Racket, to be more specific) so my first experience with programming was purely functional (I am very thankful that my school chose to do this). I think what I've been getting caught up with is a false dichotomy I've created in my head between declarative and imperative programming--something along the lines of "you can either do it the imperative or declarative way and they're completely separate", rather than consider them as interrelated. – jah Jul 24 '15 at 18:27