No silver bullet but subjective trade-offs
The other day, I was reading Carson Gross essays on htmx.org. It put certainties I had when I was a younger programmer in perspective.
I have been an advocate of TDD, Clean Code, SOLID and hexagonal architecture for a while now, I even did training about these concepts.
I have been taking separation of concerns very seriously and seeing for instance HTML, JavaScript, and CSS in the same file used to shock me. Imagine my reaction when React and JSX came out!
Does all this orthodoxy worth it? It leads to more classes, more abstraction and can lost the reader. Sometimes, a little bit of repetition, a controlled coupling between components can do no harms, has a light impact on testing and don't scare less experienced developers.
I have not tested HTMX yet, but I'm a fan of web components which collocate HTML, CSS and JavaScript yet provide standard reusable pieces of UI. It allows you to narrow the scope of styling and interaction implementation. That's the principle of the Locality of Behavour.
Until recent past. I could not imagine using onclick tag attribute to bind a web UI part and behaviour implemented in JavaScript, yet that's a great way to show where an event is handled.
Orthodoxy is good. In the past, reading Clean Code saved me from being a really bad programmer. However, experience can help you to take a step back and do enlightened subjective trade-offs.
I read this silly quote attributed to Bruce Lee once that illustrate this perfectly.
Before I studied the art, a punch to me was just a punch, a kick was just a kick. After I'd studied the art, a punch was no longer a punch, a kick no longer a kick. Now that I understand the art, a punch is just a punch, a kick is just a kick.For further readings, I recommend the Grugbrain essay and listening to this episode of Dead Code podcast.