r/coding • • Aug 05 '19

Why Declarative Coding Makes You a Better Programmer

http://minborgsjavapot.blogspot.com/2019/08/why-declarative-coding-makes-you-better.html
3 Upvotes

7 comments sorted by

25

u/yoomiii Aug 05 '19

Writing all the code to achieve the desired goal yourself in the imperative approach and using, for example, the pre-made sum and groupingBy functions in the declarative approach is not a fair comparison. You should either implement those functions in the declarative example or import some magically previously defined function sum() in the imperative approach, which would make it a one liner.

7

u/Kerbobotat Aug 05 '19

You are right. This is a rigged test from the get go.

5

u/vordrax Aug 05 '19

I agree. I like to use LINQ quite a bit in C#, which allows you to do a lot of functional-style programming, like what is featured here. But saying "use the .Sum() aggregate feature instead of re-writing it yourself" isn't really useful, except as an exercise to let you know that there are aggregate functions available to you. And it isn't declarative all the way down, their .sum() is definitely going to be defined in an imperative way somewhere. All this article is telling me is that it is useful to be familiar with the tools and libraries available to you. I suppose it can also be inferred to mean "if you are writing libraries, you should write them in such a way as to support declarative programming", but that isn't what it's saying.

0

u/mmirman Aug 05 '19

If you had a magically previously defined function "sum" how would justify it not being called declarative?

Declarative literally means "in the fashion of declaring." Here that would mean declaring functions. In software it has come to mean "programming without explicit control flow." The second you add the "sum" function call you hide the control flow making it declarative.

Any way, what reasonable language doesn't have magically previously defined "sum" library functions? I mean, its like the simplest thing you could have in a library.

15

u/snowmountainjc Aug 05 '19

Isn't advertising against the community rules?

11

u/Paddy3118 Aug 05 '19 edited Aug 06 '19

The author has a skewed idea of declarative programming. If it's declarative, why the need to explicitely change the type of the return value of sum? It looks more like functional style; and if the author doesn't know that then ...

6

u/guoyunhe Aug 05 '19

Thanks for the other comments, so I can save some time not reading the article.