4 ms·
In declarative systems, you want to explain the final end-state. Often your requirements on the final end-state involve some predicate logic. I want (A and B)
by rocqua 4y ago
In declarative systems, you want to explain the final end-state.
Often your requirements on the final end-state involve some predicate logic. I want (A and B) or C. Using an Or makes sense, if you want your declarative logic to work on both windows and linux. Or you want configurable declarative logic, or you want to be easily able to manually change the files.
A very natural way to do predicate logic is "if A is true, then B should be true". That is logically equivalent to "B or not A". But letting people write "if A, then B" is just nicer.
Hence declarative logic is much nicer with "if statements".
Perhaps another way to view this is that many declarative systems "build" their description of the desired end-state imperatively. I wouldn't say that applies here, but I could imagine cases where you want to say 'for all elements here' which might be best solved with a for loop.
- aatd86 4y agoI understand. But as you seem to hint at, it seems that "declarative" logic is still an imperative concern due to insufficient specification of the declarative framework. Which is fine in some cases. It is still control flow at a somewhat meta level. But taking the example of a declarative definition of a UI tree, changing node identity using "declarative" if statements seems like a breach or even a smell from a declarative point of view. The same way, for eachs are not necessary in the declarative layer. That can just be array iteration in the imperative/data layer.