Hacker News new | past | comments | ask | show | jobs | submit login

Functional and declarative are the same to me



I think what the article intended by “declarative” is roughly occupied by the “logic programming” paradigm and DSLs like SQL. If my intuition is right, they have a lot of conceptual overlap. But they differ mostly in how much they realize a goal of “what, not how”.


They're related, but "declarative" is a broader category that includes relations. Functions are a special case of relations (see also: prolog, datalog, sql...).


You can write declarative code in an imperative language, and you can write non-declarative code in a functional language (eg IO monad). So IMO they can’t be related.

That’s assuming that „declarative“ means „describing outcomes rather than describing process“.


You can write functional code in an imperative language and you can write imperative code in a language like Haskell, but that’s irrelevant.


They are orthogonal. React (FC) is a declarative _and_ functional approach. The declarative part is where React code describes what should be rendered, instead of adding/removing DOM elements manually.

The old React is not 100% functional (partially OO), but it still is declarative.


They're not orthogonal. I believe one is a subset of the other, but at a minimum they overlap.


Using extremes for both, that would mean there is overlap between languages like Haskell and languages like SQL?

(Edited for clarity)


Well… I’m not sure how helpful that example is, but yes you could probably find something in common between SQL and Haskell, and on the other hand, no, what I said did not mean that.

Look up Graham Hutton’s writings on relations. He has published quite a bit about this, and he knows a thing or two about functional programming.


I think relations are not a precondition for something to be called declarative programming. Most definitions I‘ve found are way broader and generic.


I never claimed they were, and I don't know if they are. But relations are in the category of declarative, and are a generalization of functions.


I'm a biologist that doesn't understand what's being talked about on this thread at all (a definition of "state", and its relation to other computational parameters would be nice). But I think I can pull an analogy from ecology that might be useful here.

When a bird population starts speciating along, say, the arctic circle, you have a line of a bunch of closely related sub-species that can interbreed with the sub-species nearest them.

Sub-species 1 ... Sub-species 2 ... Sub-species 3 ... Sub-species 4 ...

1 can breed with 2. 2 can breed with 1 and 3. 2 can't breed with 4 because they are too far apart, but if a 4 came to the territory of a 2 they could breed. Etcetera.

Eventually You get a whole circle of interbreedable sub-species as they spread across a circle of arctic latitude around the world:

1 ... 2 ... 3 ... 4 ... 5 ... 6 ... 7 ... 8 ... 9 ... 1

But once you get to that point you find that sub-species 9 and sub-species 1 can't, or won't, interbreed anymore. They are now two entirely separate species despite coming from the same origin and living right next to each other.

However none of them can interbreed with a complete separate lineage, such as wolves.

TLDR: The overlap is before the extremes, not between them.


React is neither reactive nor declarative nor functional.


Instead of stonewalling, please explain what React is in your opinion.

Edit: I mean it’s called „Functional components“, are they lying?


No, the React team means that they use JavaScript functions as the preferred authoring experience for React components. React components often have side effects & internal state and that's not necessarily a bad thing, notwithstanding strict mode.


Functional programming doesn’t mean no side effects though. At some point, every language/platform has to have them, or it can’t be used for dynamic inputs.

React (can) have referential transparency and up to a degree immutability (yes hooks are not side effect free, but so isn’t the IO monad).




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: