100 Days of Code Day 82
It turns out my desire to improve the run-length-encoding exercise evaporated overnight. Truthfully doing it with grep only works well because this is a toy version of run-length encoding. Instead I pressed ahead, and today’s exercise is Darts. You throw a dart at the target and compute a score based on distance from the bullseye. I thought I was being optimized by leaving the number as distance squared. Someone else used a higher order find() call, and someone else used a Math.hypotenuse() call I didn’t know existed. It was only about 8 lines of code so I am not going to optimize this one either.
I finished the HTMX book. I was getting disappointed in the last two chapters.
Chapter 5 has you implement a email format verifier. I know it is a contrived example for a book, but it seems like that would have been better to do in Javascript and not involve a server trip each time you leave the field. Yes you would also need to verify it on the back end too. Feels like a scaling problem waiting to happen if you ping the server for things that can easily be done locally.
I had bigger problems with Chapter 6. I did feel the need to gold plate that one. It makes a data/edit form that you can switch in an out. The first problem is that the form pulls up dummy data every time you reload. This especially ruins the cancel button which throws away all changes, not just the one you did most recently. Data also wasn’t being saved just rerouted back. I really wanted the id parameter being passed around to matter too. I eventually saved the data in a dictionary on server process (no, I will not add a database). Then I made a new endpoint just to read the user, and added hx-get=”/user/1″ hx-trigger=”load” to make it load the data from the server on load.
The other problem is we are repeating HTML a lot. There is no single source of html as both the page and the server are sources and could get out of sync easily.
My opinion of HTMX based on the book. It isn’t bad. I like that it is much simpler than something like React/Angular/Vue. I don’t like that it seems like everything quickly falls back to a call to a service. HTMX is marketed as a way to get rid of JavaScript frameworks and to minimize the amount of JavaScript in general. So lots of server calls might be expected.
I also don’t like that your service pretty much needs to return html back to the page. It makes it less adaptable to using 3rd party services and I don’t like having two sources of HTML.
In summary, for small projects it is probably good, for big ones probably not scalable enough. Not bad, just niche. It might be good for a freelancer doing small projects.
