DEV Community

Discussion on: Declarativity Comes at a Price

Collapse
 
kephas profile image
Nowhere Man

What I get from this is that you tried do transform code that was problematically promise-heavy to a more declarative form and that form didn't solve anything.

Am I missing something?

Because the only takeaway I see is that transforming code to a declarative form isn't magical in that it would solve any deficiency of the underlying code.

I don't see how that supports the notion that declarative code might be too costly.

Thread Thread
 
oleggromov profile image
Oleg Gromov • Edited

Declarative code itself might be not pricey at all - it's clean and nice, no problems.

My example shows that sometimes transformation to declarativity might cost a lot - because it is hard to make a generalized solution. Could I make a config to perform request in any possible variations? Yes, definitely. Is it worth it? Well, that depends on the use cases, your will and budget to make an abstract solution and whatsoever.

Perform a mental experiment: when you use functional and declarative lodash or underscore it costs you nothing on the surface. But somebody spent substantial time separating, coding and debugging primitives you use. It must sound undoubtedly true. And then imagine your project and you, willing to write declarative nice code but lacking needed libraries. Won't writing a one on your own be way to expensive? It might - that's my point.

Either way, there're perfect examples in the comments related to hidden complexity of the computations or too domain-specific solutions like React, for example.

Thread Thread
 
kephas profile image
Nowhere Man

But transforming to any different form might cost a lot. So again, it says nothing about declarativity and only about code transformation.

Transforming code to CPS might cost a lot. Transforming code to SSA might cost a lot. Transforming code to OOP might cost a lot. etc…

But writing declaratively from the start? Well, then the odds that it would cost anything substantial are significantly lower!

I wouldn't start by writing a whole library, I would just write the declarative functions I need. That's actually how functional programmers work… And it's not hard when you are used to it.

Like structured programming, OOP, concatenative programming, logic programming. Like any style, actually.