Would you mind giving me an example of something that’s declarative vs imperative? I see this distinction made all the time and for the life of me I still don’t understand it.
Or rather, I’ve never seen “declarative” code that I’ve liked. I watched a YouTube video once wherein two bits of code achieved the same thing, but one was imperative and the other declarative. I preferred the “imperative” code every time because I could actually read it, see what was going on. The “declarative” code seemed like it was obfuscating something or engaging in a bit too much magic for my tastes.
All the cool kids prefer declarative though, so I’m wondering what I’m missing.
it is about telling what you want instead of how to do ("computer thinking"). so let's say you want all numbers from 10 to 14 excluding 13, 15, 19 and 23. In haskell you do `[x | x <- [10..24], x /= 13, x /= 15, x /= 19, x /= 23]`, which is declarative. In imperative programming you generally would need to do control flow like a for loop. So declarative programming is way more expressive, as in functional programming like haskell it borrows many mathematical notations.
I find declarative programming like functional better for higher level programming, while Torvalds for example likes C for Linux development because it is closer to how computers work (while providing the needed abstraction than programming in assembly for example).
but i don't think the argument for it really makes any sense for OP's comment. As an user or even packager you hardly use actual functional concepts. You're mostly dealing with a JSON with some functions for declaring the system, not some crazy Haskell shit. It is just that it takes time to learn new stuff, and stuff that have concepts you're unfamiliar with takes a bit longer. And it is true that the curly braces, function arguments, and some other stuff can look kind hard to decipher, but in general it's a familiarity thing.
Or rather, I’ve never seen “declarative” code that I’ve liked. I watched a YouTube video once wherein two bits of code achieved the same thing, but one was imperative and the other declarative. I preferred the “imperative” code every time because I could actually read it, see what was going on. The “declarative” code seemed like it was obfuscating something or engaging in a bit too much magic for my tastes.
All the cool kids prefer declarative though, so I’m wondering what I’m missing.