Chris Brannon's Blog rss

Justifying Technical Choices

After my HTMX post the other day, a friend was asking me about my technical choices. “Why do you use HTMX?” “Why do you use that Lua Scheme hybrid, when you could just use Lua?” (The second question was of course referring to Fennel).

When it comes to open-source or personal use code, the most correct answer is always: because I wanna. Do your thing. You really don’t have to justify your choices to anybody. A “give zero fucks” attitude is a thing worth cultivating in life sometimes.

Now that my brief rant is done, those are actually some questions that have interesting answers.

Why HTMX?

The short answer: because it’s declarative. No, it’s not fully declarative, because you have to load the htmx.js or htmx.min.js script from somewhere. But once you’ve done that, your browser supports a kind of extended HTML for generating dynamic content, declaratively! Arguably, HTMX could be supported directly in browsers, and perhaps that would be a very cool thing, because then you wouldn’t need to load any JS at all.

Declarative code has some really nice properties. It’s one reason why SQL has stood the test of time. I’d also argue that it is more secure. That’s harder to prove, but I’ll try and justify my assertion.

HTML is easier to introspect than JavaScript. “View source” is your friend! This is especially true when you consider that so much JavaScript on the web today is produced by compilers, minifiers, obfuscators, and other tooling. You might as well be looking at binary blobs, even though the content is technically text. I call this human-hostile JavaScript “dog vomit”. It’s the description that occurred to me when I was working at Google in 2012 and first saw the output produced by their Closure JS transpiler.

An introspection-friendly web is, by its very nature, a more secure web. I can view the source of a declarative webpage and assure myself that it isn’t trying to mine crypto on my box. Which, by the way, is why big tech hates URLs and view source etc: because they want to do nefarious things with your computer, like show you ads. It’s also why you probably won’t see an equivalent to HTMX in something like Chrome, even though that would be awesome.

Why Fennel?

I like Lispy languages. One reason I like them so much is that they impose less cognitive load. My friend who was asking me questions about my technical choices was telling me a story last week, about how he got the wrong result from an SQL query because he forgot or didn’t realize that and took precedence over or. There are basically three solutions to that problem:

  • Remember a bunch of precedence rules! Here’s where cognitive load comes in.
  • Insert parens aggressively when you’re unsure of precedence. Now you have an infix language with useless parens all over the place, and it’s hard to read.
  • Just use a Lispy syntax!

Yeah, I prefer option 3. It’s so much easier for my little brain.

So why Fennel, specifically? Fennel is basically a Lispy veneer on top of Lua. I could have gone with another Lisp. I’m a fan of Chicken Scheme, for instance. That one compiles to C. But I wanted to experiment with Fennel, because I think Lua itself has some desirable qualities.

The cool thing about Lua is that it is aggressively portable. It basically runs on anything recently modern with a C compiler, and by recently modern, I mean the 1990s. It’s also very lightweight. It runs on my wireless access point. That’s what I call portable! LuaJIT, an alternative Lua implementation, is blazingly fast if you need that, though it is not going to be as portable as stock Lua from PUC Rio. There’s a fairly large community around Lua, and users have produced numerous extensions over the years. A Lisp that compiles to Lua gives me the syntax I love with the advantages of Lua.

Posted 22 Dec 2023 03:32 by chris Updated: 30 Mar 2024 15:46
Tagged: Fennel HTMX Lua rant