Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The imperative approach would be to query Postgres and do the aggregation yourself. The declarative approach would be to query Postgres and ask it to do the aggregation via GROUP BY.

These solutions don't necessarily have anything to do with the concepts as you name them.



>These solutions don't necessarily have anything to do with the concepts as you name them.

Why not? A "GROUP BY" syntax is -- relatively speaking -- more declarative than handwritten imperative code looping through a cursor and dynamically adding to a keys-values data structure to accomplish the same idea.


That's not "more declarative", that's just "more high-level". Using higher-order functions does not suddenly turn imperative programming into declarative programming.


>Using higher-order functions does not suddenly turn imperative programming into declarative programming.

I wasn't talking about strict definitions of "declarative programming" vs "imperative programming" to satisfy language lawyers.

It was a continuation of the subthread discussion started by carlmr asking why declarative is better: https://news.ycombinator.com/item?id=30098793

So it was just talking about aspects of "declarative" in general...

The idea is at a small scale, one can compare an imperative loop construct to the more "declarative" syntax that accomplishes the same task. Yes, the "more declarative" syntax will be a higher-level abstraction.

Another example of the micro-instead-of-macro type of discussion was C# when it added LINQ (declarative quasi-SQL) and async/await (declarative futures). The language designers and tutorials used the word "declarative" to describe those new language features even though C#-as-a-whole is not formally categorized as a declarative language. Does using LINQ turn C# into a declarative language? No, but nobody claimed that.


A higher-order function is a function that takes a function as an argument which doesn't have anything to do with the discussion at hand.

But you are right that it is higher level in that it abstracts away the logic behind GROUP BY. In this sense, all declarative programming is higher level.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: