3 ms·
As others have pointed out, I wouldn't necessarily call this "declarative programming"--this actually is more what I'd call "literate programming". That's seman
by kerkeslager 6y ago
As others have pointed out, I wouldn't necessarily call this "declarative programming"--this actually is more what I'd call "literate programming". That's semantics, but I will add that in my opinion, literate programming is way more effective than declarative programming.
Literate programming is just syntactic sugar around functional programming. For example:
qux(bar(foo,baz),garlply)
...becomes:
foo.bar(baz).qux(garply)
This is the sort of thing that typically emerges when you have immutable objects, and demonstrates a sort of equivalence between immutable OOP and FP. This is why I don't generally care about functional programming versus object oriented programming debates: they're equivalent if you don't mutate. I'm much more interested in immutability than a slavish loyalty to functions over methods. And I tend to agree with the OP that literate programming is very effective.
What people usually mean when they say "declarative programming" is they want to write a config file in, say, JSON, and have that be their program. But that would mean that the implementer of the language would have to think of every possible way that you could possibly want to configure the program, so they start adding customization points where you can write code in an actual language which is called in certain spots. So now you have to know how to program in a normal language, and know how all the different customization points work. Oh and while you're doing that, you can forget about getting anything helpful like a stack trace, because it was declarative so you don't need to worry about what is calling what, right? So you get things that just fail silently and you don't know why, like:
class Mail(models.Model):
ordering = '-received'
sender = models.EmailField()
receiver = models.EmailField()
received = models.DateTimeField()
body = models.TextField()
This orders by received ascending, even though you clearly are telling it to order by received descending... have fun figuring out why! I'm picking on Django here but it's actually one of the best examples of declarative programming. The problem isn't that they didn't validate for this case: I don't think they could do that reasonably. The problem is that it's not really possible to implement declarative programming in a way that catches all the possible errors of this sort.