Live data from Hacker News

Imperative vs. Declarative

latentflip.com

11–20 of 53 posts

Re: Imperative vs. Declarative

#11
It is not just as programmers. Consider, most cookbooks. Then consider the directions that come with Ikea furniture. Of course, the real beauty of both of those examples, is that they are a mix of declarative and imperative instructions.

For some reason, it seems we programmers are adamant that it must be one or the other. Consider all of the examples, either purely imperative or purely declarative. Why not both?

Re: Imperative vs. Declarative

#12

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 th…

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

#13
post #11

It is not just as programmers. Consider, most cookbooks. Then consider the directions that come with Ikea furniture. Of course, the real beauty of both of those examples, is that they are a mix of declarative and imperative instructions. For some reason, it seems we programmers are adamant that it must be one or the other. Consider all of the examples, either purely imperative or purely declarative. Why not both?

well one declares variables:

    - given a pan
    - given 3 eggs
    - given a little of olive oil
then one executes orders :

    - add the oil in the pan
    - break the eggs and add them in the pan
    - cook the eggs fo 5 mins
    - serve the food hot
so i guess one is never really doing either pure declarative of imperative cooking/programming ?

I like the cookbook metaphore for programming.

Re: Imperative vs. Declarative

#14

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 th…

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

#15
post #12

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 th…

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 ?

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

#16

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 th…

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.

[deleted]

Re: Imperative vs. Declarative

#17
post #13
post #11

It is not just as programmers. Consider, most cookbooks. Then consider the directions that come with Ikea furniture. Of course, the real beauty of both of those examples, is that they are a mix of declarative and imperative instructions. For some reason, it seems we programmers are adamant that it must be one or the other. Consider all of the examples, either purely imperative or purely declarative. Why not both?

well one declares variables: - given a pan - given 3 eggs - given a little of olive oil then one executes orders : - add the oil in the pan - break the eggs and add them in the pan - cook the eggs fo 5 mins - serve the food hot so i guess one is never really doing either pure declarative of imperative cooking/programming ? I like the cookbook metaphore for programming.

It is actually even more interesting in some respects. You consider "break the eggs and add them in the pan" as an imperative command; yet it has to be learned. Just going off of that there are so many ways it can go wrong it is frightening. Consider, how do you break the eggs, and do you add the entirety to the pan? (yes, I just watched my 3 year old try this recently.)

So, don't get me wrong. I'm all for declarative actions. I just think the "purely declarative" approach that many languages try and impose is a useful aberration when you consider how the vast majority of "programming" is done.

Re: Imperative vs. Declarative

#18
What is the result of procedural programming? Functions that can be used declaratively! The purpose of procedural programming is to encapsulate and consequently eliminate "telling the 'machine' how to do something".

PS: What happened to 3GL vs. 4GL?

Re: Imperative vs. Declarative

#19
post #12

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 th…

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 ?

An evaluation strategy is imperative but the logic that the strategy operates on doesn't have to be.

Re: Imperative vs. Declarative

#20
post #12

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 th…

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 ?

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?

Post reply on HN