4 ms·
> the whole functional programming schtick isn't for me. I cannot for the life of me understand half the stuff I read (the Nix language, that is). I still don't
by xyzzy_plugh 5y ago
> the whole functional programming schtick isn't for me. I cannot for the life of me understand half the stuff I read (the Nix language, that is). I still don't see why all this couldn't have been written in say, Lua for example. Nix (and NixOS), is overwhelming.
It's because you're still thinking about this imperatively, when you should be thinking declaratively. I was in the same boat as you, but everything has recently begun to gel and it's much easier to read Nix configs.
The language is definitely intimidating but once I wrote a few small derivations for my own use, everything became clear almost immediately, much to my surprise. Try to do everything as declarative as possible (use flakes) and you'll have a considerably more consistent experience.
- rewgs 5y agoWould 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.
- iswkq 5y agoit 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.