News for hackers. Stuff that matters.
Re:Imperative vs. Declarative by hackinthebochs on Tuesday April 02, 2013 @01:05PM (#5480610)
I'm not sure I agree with some of the examples in the article. The examples used paint declarative programming as basically abstractions over details. The problem is that there is no line where an abstraction crosses the boundary into declarative programming. It's not really about abstractions but about control flow. If your code has a specific order it has to run in, then its imperative as you're still describing the steps needed to perform the action. SQL is declarative because you're describing the output set rather than the steps to generate it. Functional languages are considered declarative because of the fact that pure functions can be rewritten, optimized, lazy evaluated, etc by the runtime. I have a hard time considering map/reduce/etc in isolation as examples of declarative programming, as they're usually used in conjuction with an algorithm that most definitely has a defined execution order.
Re:Imperative vs. Declarative by richardwhiuk on Tuesday April 02, 2013 @01:25PM (#5480729)
I agree. I don't recognize the examples here as declarative programming.

SQL and Prolog are both examples of declarative programming, so is Make to an extent. Using a map function doesn't make JavaScript a declarative programming language - it's a functional programming concept, not a declarative one.

Re:Imperative vs. Declarative by kd0amg on Tuesday April 02, 2013 @01:50PM (#5480905)
it's a functional programming concept

That doesn't keep it from being a declarative thing.

Re:Imperative vs. Declarative by camus on Tuesday April 02, 2013 @01:19PM (#5480690)
so what would be declarative programming ? does it even exist? i mean, at some point you need to write some logic , and logic is imperative. Let's take a html file. It is declarative. but the underlying logic is written somewhere else. so you cant really have pure declarative programming? if it is possible how ?
Re:Imperative vs. Declarative by hackinthebochs on Tuesday April 02, 2013 @01:39PM (#5480836)
I think the important distinction is what level of detail is the logic being passed off to the environment for translation into machine instructions. If the environment has freedom to decide exactly how to fulfill your request, then its declarative. Imperative is when your logic is specified such that there is little room for the environment to make implementation decisions.

In the case of map/reduce, if these functions are implemented in your language (say in jquery) then its not declarative as your implementation is still being specified. If you are actually talking to your environment in terms of map/reduce, then those methods are declarative. On the other hand, if we consider jquery as a part of our environment, perhaps it does make sense to consider it declarataive?

Re:Imperative vs. Declarative by icebraining on Tuesday April 02, 2013 @01:29PM (#5480754)
I think you're mistaking the program for the implementation. A program can be purely declarative; the fact that we need to create an imperative representation of it to run it on a computer doesn't change that.
Re:Imperative vs. Declarative by stonemetal on Tuesday April 02, 2013 @01:37PM (#5480816)
An evaluation strategy is imperative but the logic that the strategy operates on doesn't have to be.
Re:Imperative vs. Declarative by camus on Tuesday April 02, 2013 @02:30PM (#5481217)
great point !
Re:Imperative vs. Declarative by scott_s on Tuesday April 02, 2013 @02:57PM (#5481383)
Yes. Read up on Prolog.