Benjamin-Philip

Benjamin-Philip

I’ve noticed that in other languages, there is a practice of rendering HTML with functions (as in Elm) or with a DSL (as in the case of Crystal in the Lucky framework). This approach has a number of advantages over templating:

  1. HTML is parsed far more easily because there is no parsing to do: the developer writes out the AST.
  2. HTML is written in the same syntax as all your other code
  3. It is much more easier to extend your rendering - define a new function or new macro

A major effect of No. 1 is that validation of HTML becomes a lot more easier to implement. Validation in this way would have appeared a lot sooner than it appeared with EEx in the form of HEEx (which I believe only became the norm sometime last year)

No. 2 is a big advantage for me because I don’t have to deal with verbose SGML syntax, and more significantly, I have syntax highlighting, completion etc. working out of the box when I inline templates (for liveviews for example). DSLs will help reduce to complexity of editor configurations needed to deal with inline templating.

No. 3 basically means that function component like functionality was available from the beginning. No major extra effort has to be made to provide a good syntax to call functions because you just use standard Elixir syntax. Before Heex (for me at least) trivial things were duplicated and non-trivial things had a verbose function call.

Those are the first benefits that came to mind, and there may be more. Of course, there is a disadvantage, that is you first need to learn the DSL and possibly its nuances as well before you can get productive. For some this is a problem, but for most (I think at least) it is not. This is analogous to the question of DSLs for SQL queries or not in languages where ORMs are not required or aren’t the norm. Some use them, some don’t.

No other disadvantages come to mind, and there may be more, but overall it seems to me that DSLs are not inherently worse than templates in other way. There are nice to have benefits of using them though. Perhaps with DSL-like templating languages like haml you get the (some of at least) best (or maybe worst!) of both worlds.

Now the question I have is this: Why do we not use DSLs (or plain functions sans macros) for rendering HTML in Phoenix? Was it because that is what Rails did, and there weren’t any problems with it to need such a change? Or is there some other reason? I know for a fact that there are no technical limitations preventing such a approach. Though I haven’t read the book, I believe Chris McCord himself writes such a DSL in Metaprogramming Elixir.

Showing Posts 1 to 1

eahanson

eahanson

I’ve used Temple in the past and enjoyed it. I’d like to get back to it one day.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
GES233
I’m posting this in response to Jose’s recent tweet (Cr. link) : People are sleeping on Elixir for a coding harness: Hot-code swappi...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
durvia
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes. We’re a small ...
New
AstonJ
This might be a bit disturbing for some but it’s happening - computers running on living human neurons. They’ve made them smart enough t...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews