DEV Community

Discussion on: Declarative vs Imperative - a Thoughtful Comparison

 
efpage profile image
Eckehard • Edited

Well, first let me thank you for your thoroughly analysis. I´m pretty sure it depends much on the task which approach plays better.

You should also see: The DML-library I´m using is just a wrapper to the HTML-DOM-API, so what you see is the whole machine, nothing much behind. There is no big framework in the background that does all the heavy lifting for me. Some will find this a disadvantage, but it make the usage very lightweight and compatible to almost anything.

The ToDo-App was ready, so the filter was just not implemented. This can be handeled by the base app, but as the todoObjects handel their state autonomously, i would prefer to let them control their visibility too. So, I just would send a broadcast to all toDos and let them decide. As DOM can hide elements, this would be the preferred method.

You are right, the solution for "readObj" is not very elegant, as setState is called twice. This would be simple to avoid, but usually we would have a better organized persitence class in our projects that does the job. It´s the kind of "better do it double than never" thing you will find sometimes, but that does not happen very often.

But, this has nothing to do with "spaghetti": As the objects are tightly coupled to the DOM (in fact, nobody else has access to the DOM elements than the todoObj), state management has to be done by the objects. As the DOM elements are owned by the JS-objects, there is nothing wrong about this.

With the serialization you are pretty right, we always need som "tools" to do the job. But that was never a topic I got headaches from.

Bottomline I would say, we can do the job using both approaches.

  • Possibly you would get some more help from SolidJS,
  • my approach can be used as a webComponent, combined with Solid, React, Angular or even Typo3 (which we have already done)

There are pro´s and con´s on every approach, so I think it is not worth trying to win the contest. We can just try to get the best of each world.