r/programming • u/nfrankel • Aug 05 '19
Why Declarative Coding Makes You a Better Programmer
http://minborgsjavapot.blogspot.com/2019/08/why-declarative-coding-makes-you-better.html
0
Upvotes
r/programming • u/nfrankel • Aug 05 '19
17
u/[deleted] Aug 05 '19
The thing I've realized about "declarative coding" is that it's actually not a separate type of coding. There's no hard line there. In the way they're defined it feels like it is, but in practice, declarative code is basically higher-level code.
And of course, higher-level code is to be preferred. But the most important part about being able to write high-level code is to have the habit of writing your own "declarative" abstractions and high-level tools to express the rest of your code with.
Using what the language offers, like filters/map/reduce, LINQ and so on, that's great. But if you stop at what's built-in, you're missing vast opportunities in making your code higher-level.
Functional programming practitioners do this instinctively. They'd create for themselves highly composable high-order functions designed for a task, so they can express a program in a surprisingly tight and minimal way. Most mainstream programmers would just grunt through, copy-pasting samples from the web, and using whatever APIs are available out of the box.
So in a way, it's not that declarative coding makes you a better programmer as much as... being a better programmer is in large part about factoring your code declaratively (high-level).