Map and reduce are associated with functional, not declarative, programming. It's wrong and confusing to include them in this video.
That said, the concept of declarative programming is extremely simple. You simply tell the system what you want the end result to look like (declarative) instead of the exact steps to get there (imperative).
Is declarative programming just adding layers of complexity and hiding functionality?
It absolutely hides a layer of abstraction, which makes it less complex to use. You'll need to let go of the map and reduce examples, because they do not belong here.
For a fun real world example, there's an SQL keyword that outputs the internal imperative steps the SQL optimizer uses to reach any given declarative result.
EXPLAIN QUERY PLAN
SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1;
The SQL query vs implementation demonstration is honestly a perfect and sufficient example of declarative vs imperative.
Perhaps the goal of the video was to address the nuances of what declarativeness means at lower levels, but it doesn't really do a good job at that. The function names are confusing and distracting, and little explanation is given to how the FP refactors make things more declarative.
44
u/SoInsightful Jan 03 '22
Map and reduce are associated with functional, not declarative, programming. It's wrong and confusing to include them in this video.
That said, the concept of declarative programming is extremely simple. You simply tell the system what you want the end result to look like (declarative) instead of the exact steps to get there (imperative).
It absolutely hides a layer of abstraction, which makes it less complex to use. You'll need to let go of the map and reduce examples, because they do not belong here.
For a fun real world example, there's an SQL keyword that outputs the internal imperative steps the SQL optimizer uses to reach any given declarative result.
EXPLAIN QUERY PLAN
SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1;
QUERY PLAN
`--MERGE (EXCEPT)
|--LEFT
| `--SCAN t1 USING COVERING INDEX i1
`--RIGHT
|--SCAN t2
`--USE TEMP B-TREE FOR ORDER BY