marick

marick

About how Phoenix renders iodata rather than strings

As a new Phoenix user, I was happy to discover that Phoenix doesn’t render strings but something rather like Erlang iodata. That lets me use a more builder-style approach for creating chunks of HTML pages - but without having to use elaborate infrastructure. Seems to be working nicely so far.

In any case, I thought I might write up a blog piece about what I now understand about Phoenix rendering and iodata. As a newbie, I’ve probably gotten things wrong. Corrections welcome here or at http://blog.roundingpegs.com/taking-advantage-of-phoenix-rendering-and-iodata-part-1/

Most Liked

OvermindDL1

OvermindDL1

Nice, although one thing to note is that although eex accepts ‘nil’, it should not really ever be used. Returning an empty list of [] is always a better approach than returning nil as it then allows it to be embedded further without worry. I consider nil’s returned from a function that could ever possibly end up going to a template as a bug.

Other than that your article looks like a fairly accurate high level view. :slight_smile:

michalmuskala

michalmuskala

I honestly don’t think this is a good idea. Erlang uses nil to mean empty list only because that’s the naming in lisp. But I don’t think there’s a strong technical reason for it.

Erlang itself most often uses the atom undefined for uninitialised state, so I think using an atom for this purpose in elixir makes the most sense.

josevalim

josevalim

Creator of Elixir

[] is not Erlang’s nil. That notation is used only in the abstract syntax tree and in Erlang code nil has exactly the same as nil in Elixir.

Plus [] has the notion of cardinality, which nil is devoid of. Given Elixir has both collections and base types, I believe it is important to represent nothingness without a notion of cardinality built-in.

Where Next?

Popular in Discussions Top

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement