Using Elixir to Develop

72 views
Skip to first unread message

Allen Wyma

unread,
Sep 28, 2017, 9:17:35 PM9/28/17
to Zotonic developers
Hi,

Does anyone have a guide with how to use elixir with Zotonic? We're a ruby house that's looking to switch to elixir, but sometimes we get projects that seem to work better for a CMS. When I saw this project, I was quite amazed and we'd like to start to experiment a bit with it.

Is it possible to have a guide of how to use elixir with Zotonic? I've tried looking a bit at the code for erlang, and it includes references to hrl (erlang macro/header files) which are not supported in elixir. This is probably my biggest question of how to translate over the code.

Thanks

Marc Worrell

unread,
Sep 29, 2017, 2:51:30 AM9/29/17
to zotonic-d...@googlegroups.com
Hi Allen,

Two weeks ago David de Boer and I had a look at how Elixir and 
Erlang could be mixed.

We concluded that it all should be possible to do with the master.
But also that we didn’t know enough of Elixir to make it frictionless.
So we need some help with this.

The master is split in applications, and those will all be pushed to Hex.
That is a good start for any Elixir setup, I guess.

The main zotonic.hrl is mainly included because we like to poke around in 
#context{} (which we shouldn’t) and to use the ?DEBUG/1 macro.

There are some other macros in there, but they are not essential.
So it is not really needed for building modules etc.

We welcome help to make Zotonic work with Elixir!

Arjan could probably help as well - though he is very busy right now.

Cheers, Marc


--

---
You received this message because you are subscribed to the Google Groups "Zotonic developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotonic-develop...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kai Janson

unread,
Sep 29, 2017, 4:10:33 AM9/29/17
to zotonic-d...@googlegroups.com
Some of the things in the hrl file could be replaced by Elixir macros or functions?

Sent from my non-google-device

Allen Wyma

unread,
Sep 29, 2017, 4:11:56 AM9/29/17
to zotonic-d...@googlegroups.com
I’m more than willing to help out in exchange for some Dutch help? Language 4 language exchange? :)
You received this message because you are subscribed to a topic in the Google Groups "Zotonic developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/zotonic-developers/iOOAFZ8Uq1Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to zotonic-develop...@googlegroups.com.

Marc Worrell

unread,
Sep 29, 2017, 4:12:28 AM9/29/17
to zotonic-d...@googlegroups.com
Thinking of it… we do use a lot of records for all notifications and postbacks.

Are those supported in Elixir?

- Marc

Marc Worrell

unread,
Sep 29, 2017, 4:13:44 AM9/29/17
to zotonic-d...@googlegroups.com
On 29 Sep 2017, at 10:11, Allen Wyma <allen...@gmail.com> wrote:

I’m more than willing to help out in exchange for some Dutch help? Language 4 language exchange? :)

LOL,  quite some people in the core team are quite proficient in Dutch.
So that won’t be problematic :)

- M

Allen Wyma

unread,
Sep 29, 2017, 4:38:41 AM9/29/17
to zotonic-d...@googlegroups.com
Ganz geil! How to connect?
--

Marc Worrell

unread,
Sep 29, 2017, 4:46:18 AM9/29/17
to zotonic-d...@googlegroups.com
On 29 Sep 2017, at 10:38, Allen Wyma <allen...@gmail.com> wrote:

Ganz geil! How to connect?

That is German, actually.
The team is quite present on gitter.


Maas-Maarten, David and Arthur are there quite regularly.
And maybe Arjan is watching along between his busy times.

- Marc



You received this message because you are subscribed to the Google Groups "Zotonic developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotonic-develop...@googlegroups.com.

Jake Morrison

unread,
Sep 29, 2017, 4:50:04 AM9/29/17
to zotonic-d...@googlegroups.com
On Fri, Sep 29, 2017 at 08:12:53AM +0000, Marc Worrell wrote:
> Thinking of it… we do use a lot of records for all notifications and postbacks.
>
> Are those supported in Elixir?

Records are supported, here is the Elixir syntax:
https://hexdocs.pm/elixir/Record.html
Maps are generally easier to deal with than records, though, in both languages.

I have converted larger Erlang codebases to Elixir incrementally. The
first step is generally to switch the project to using using mix, the
Elixir build tool. Second is to switch to using maps for the core data
structures, so it's easier to interoperate. Then we do a "mechanical"
conversion from Erlang to Elixir, as the language semantics are
essentially the same. Depending on the state of tests in the project, we
would either use the Erlang tests to validate that things are still
working properly, or write tests using Elixir's ExUnit and friends.
Finally we start using the syntax improvements in Elixir to make the code nicer.

For interop, doing the first two steps would make things easiest for
Elixir folks. It adds a dependency on Elixir to build the system,
though.

> - Marc

Jake

Marc Worrell

unread,
Sep 29, 2017, 5:39:40 AM9/29/17
to zotonic-d...@googlegroups.com
Can mix build rebar3 based apps?
If so then we can just provide a mix based project.

I am also thinking of using the introspection (we are using that for
notify observers) to discover if a module, filter, action or other
type of Zotonic callback module is an Elixir module.
And if so we could generate or use some glue code to call directly
into the Elixir modules from Zotonic.

- M

Jake Morrison

unread,
Oct 1, 2017, 8:19:53 PM10/1/17
to zotonic-d...@googlegroups.com
Marc,

On Fri, Sep 29, 2017 at 09:40:07AM +0000, Marc Worrell wrote:
> Can mix build rebar3 based apps?

Mix is more or less a replacement for rebar3, so they are mutually
exclusive, though largely compatible.

> If so then we can just provide a mix based project.

For Elixir users, the easiest thing is if Zotonic can be used
as a library which can be pulled in by mix/rebar from https://hex.pm/,
i.e. it's a well behaved OTP application. It might make sense
to have some mix tasks which e.g. create template modules.

> I am also thinking of using the introspection (we are using that for
> notify observers) to discover if a module, filter, action or other
> type of Zotonic callback module is an Elixir module.
> And if so we could generate or use some glue code to call directly
> into the Elixir modules from Zotonic.

Generally speaking, Elixir code is functionally the same as Erlang
code, the module atoms just start with 'Elixir.', so that may not be
necessary.

> - M

Marc Worrell

unread,
Oct 2, 2017, 6:38:40 AM10/2/17
to zotonic-d...@googlegroups.com

> On 2 Oct 2017, at 02:19, Jake Morrison <ja...@cogini.com> wrote:
>
> Marc,
>
> On Fri, Sep 29, 2017 at 09:40:07AM +0000, Marc Worrell wrote:
>> Can mix build rebar3 based apps?
>
> Mix is more or less a replacement for rebar3, so they are mutually
> exclusive, though largely compatible.
>
>> If so then we can just provide a mix based project.
>
> For Elixir users, the easiest thing is if Zotonic can be used
> as a library which can be pulled in by mix/rebar from https://hex.pm/,
> i.e. it's a well behaved OTP application. It might make sense
> to have some mix tasks which e.g. create template modules.

The master is being split in OTP apps, with the specific goal of
being reusable.

Actually, there is not much left in the ‘zotonic.app’, almost everything
is moved to the other (OTP) apps.

So I guess having a Mix (/Elixir) project that people can clone could
be a good starting point for Elixir devs.

>
>> I am also thinking of using the introspection (we are using that for
>> notify observers) to discover if a module, filter, action or other
>> type of Zotonic callback module is an Elixir module.
>> And if so we could generate or use some glue code to call directly
>> into the Elixir modules from Zotonic.
>
> Generally speaking, Elixir code is functionally the same as Erlang
> code, the module atoms just start with 'Elixir.', so that may not be
> necessary.

So if an Elixir source file defines the Elixir equivalent of a function:

observe_some_event/2

Then in the function definitions I can find just that function?
And the module itself would be loaded as ElixitSomModuleName?

That would make it quite straightforward to integrate Elixir code
into the notification system.

- M

Jake Morrison

unread,
Oct 2, 2017, 10:23:11 PM10/2/17
to zotonic-d...@googlegroups.com
On Mon, Oct 02, 2017 at 10:39:04AM +0000, Marc Worrell wrote:
>
> > On 2 Oct 2017, at 02:19, Jake Morrison <ja...@cogini.com> wrote:
> >
> > Marc,
> >
> > On Fri, Sep 29, 2017 at 09:40:07AM +0000, Marc Worrell wrote:
> >> Can mix build rebar3 based apps?
> >
> > Mix is more or less a replacement for rebar3, so they are mutually
> > exclusive, though largely compatible.
> >
> >> If so then we can just provide a mix based project.
> >
> > For Elixir users, the easiest thing is if Zotonic can be used
> > as a library which can be pulled in by mix/rebar from https://hex.pm/,
> > i.e. it's a well behaved OTP application. It might make sense
> > to have some mix tasks which e.g. create template modules.
>
> The master is being split in OTP apps, with the specific goal of
> being reusable.
>
> Actually, there is not much left in the ‘zotonic.app’, almost everything
> is moved to the other (OTP) apps.
>
> So I guess having a Mix (/Elixir) project that people can clone could
> be a good starting point for Elixir devs.

The most interesting thing is probably an example combining Zotonic with
Phoenix.

> >> I am also thinking of using the introspection (we are using that for
> >> notify observers) to discover if a module, filter, action or other
> >> type of Zotonic callback module is an Elixir module.
> >> And if so we could generate or use some glue code to call directly
> >> into the Elixir modules from Zotonic.
> >
> > Generally speaking, Elixir code is functionally the same as Erlang
> > code, the module atoms just start with 'Elixir.', so that may not be
> > necessary.
>
> So if an Elixir source file defines the Elixir equivalent of a function:
>
> observe_some_event/2
>
> Then in the function definitions I can find just that function?
> And the module itself would be loaded as ElixitSomModuleName?
>
> That would make it quite straightforward to integrate Elixir code
> into the notification system.

It's basically the same, just the Elixir compiler adds "Elixir" to
the front of the module names. So probably nothing needs to be done.

In Erlang, if you have a module foo, it would look like:

-module(foo).

-export([observe_some_event/2]).

observe_some_event(One, Two) -> ...

And you would call it like foo:observe_some_event(One, Two)

In Elixir, it would look like:

defmodule Foo do
def observe_some_event(one, two) do
...
end
end

From Erlang, the module atom would be 'Elixir.Foo', and you can call it
like 'Elixir.Foo':observe_some_event(One, Two) or apply('Elixir.Foo',
observe_some_event, [One, Two])

> - M

Jake

da...@ddeboer.nl

unread,
Oct 10, 2017, 8:21:05 AM10/10/17
to Zotonic developers
I have converted larger Erlang codebases to Elixir incrementally

Jake, can you explain the rationale behind this? Why did you want to run your apps in Elixir instead of Erlang?
 
The most interesting thing is probably an example combining Zotonic with 
Phoenix. 

This is something I’ve been thinking about for a while now. Going one step further: what about porting Zotonic to Elixir? There are a many reasons why Zotonic and Phoenix (= Photonic ;) are a great match:

1. As of yet, there’s no fully-fledged CMS available for Phoenix/Elixir. Having a stable CMS for Phoenix will enable developers to be more productive in Elixir and attract more of them to start doing Elixir in the first place. There’s definitely a demand for a Phoenix CMS: as Allen and others write in this thread and again others have told me.

2. This is also a great chance for Zotonic. As most web developers on the Beam VM are doing Elixir, it will be much easier for them to submit improvements to an Elixir CMS than an Erlang one. So by porting Zotonic to Elixir we will hopefully find more contributors.

3. The number of Zotonic contributors is rather small for such a large product. One way to solve this problem is by reducing the scope of Zotonic. Currently it has custom logic for HTTP (Cowmachine), templates (template compiler), routes (dispatch compiler) and so on. All these belong to web applications in general, not a CMS specifically. Let’s use Phoenix to take care of these. Phoenix has a (much) larger community, so it can do these fundamentals better and more efficiently than we can. Worst case, we would have to build something on top of what Phoenix ships with out of the box, such as adding adding dynamic routing. Let’s stick to what makes Zotonic unique: its flexible datamodel, performant depcache, (possibly) ErlyDTL template language. 
(As a side-note, let’s not forget Zotonic is much older than Phoenix, and Zotonic has been doing things such as real-time client/server communication before Phoenix existed, let alone added Channels.)

4. Phoenix is well-designed and properly decoupled (Plug for HTTP, Ecto for databases and Contexts for domain logic). The same cannot not always be said of Zotonic. So switching over to Phoenix will result in smaller Zotonic components written in higher-quality code.

5. Most web development on the Beam VM is happening in Elixir: if you need authentication, JSON-LD parsing etc., there are much more likely to be up-to-date, well-maintained and documented Elixir packages available on Hex.pm than a single Erlang one. It therefore makes sense to integrate with the Elixir ecosystem.

Cheers,

David


Op dinsdag 3 oktober 2017 04:23:11 UTC+2 schreef Jake Morrison:

Allen Wyma

unread,
Oct 10, 2017, 9:24:09 AM10/10/17
to Zotonic developers
I'm more than happy to help convert some pieces. I left some messages on gitter. I just couldn't get zotonic to run by itself. It would be great if there was a way I could just add them as plugs, like David was saying.

Marc Worrell

unread,
Oct 10, 2017, 1:35:34 PM10/10/17
to zotonic-d...@googlegroups.com
Hi,

David and I discussed this today and we think that there is a possibility to make a zotonic-plug in combination with a “default” site in Zotonic.

David made some notes, which I assume he will share here :)

There are some details we need to figure out, like how we are using cowboy2 and if we might want to use ecto.

Cheers, Marc

Sent from my iPhone
--

Jake Morrison

unread,
Oct 11, 2017, 7:48:43 AM10/11/17
to zotonic-d...@googlegroups.com
Hi David,

On Tue, Oct 10, 2017 at 12:21:05PM +0000, da...@ddeboer.nl wrote:
>
> >
> > I have converted larger Erlang codebases to Elixir incrementally
>
> Jake, can you explain the rationale behind this? Why did you want to run
> your apps in Elixir instead of Erlang?

I have been using Erlang since 2007. I switched my company over to
Elixir two years ago, and am very happy.

Elixir has all of the power of Erlang, with the rough edges of the
syntax cleaned off. Then it adds on powerful abstractions like macros
and protocols, as well as libraries like Ecto. And the community is
focused on having great usability and out of box experience.

> > The most interesting thing is probably an example combining Zotonic with
> > Phoenix.
>
> This is something I’ve been thinking about for a while now. Going one step
> further: what about porting Zotonic to Elixir? There are a many reasons why
> Zotonic and Phoenix (= Photonic ;) are a great match:

That would be great, and I would be glad to help.

> 1. As of yet, there’s no fully-fledged CMS available for Phoenix/Elixir.
> Having *a stable CMS for Phoenix* will enable developers to be more
> productive in Elixir and attract more of them to start doing Elixir in the
> first place. There’s definitely a demand for a Phoenix CMS: as Allen and
> others write in this thread and again others have told me.
>
> 2. This is also a great chance for Zotonic. As most web developers on the
> Beam VM are doing Elixir, it will be much easier for them to submit
> improvements to an Elixir CMS than an Erlang one. So by porting Zotonic to
> Elixir we will hopefully find *more contributors*.
>
> 3. The number of Zotonic contributors is rather small for such a large
> product. One way to solve this problem is by *reducing the scope of Zotonic*.
> Currently it has custom logic for HTTP (Cowmachine), templates (template
> compiler), routes (dispatch compiler) and so on. All these belong to *web
> applications in general, not a CMS specifically*. Let’s use Phoenix to take
> care of these. Phoenix has a (much) larger community, so it can do these
> fundamentals better and more efficiently than we can. Worst case, we would
> have to build something on top of what Phoenix ships with out of the box,
> such as adding adding dynamic routing
> <https://gist.github.com/chrismccord/1c6b6fb086d5432d4e08>. Let’s stick to *what
> makes Zotonic unique*: its flexible datamodel, performant depcache,
> (possibly) ErlyDTL template language.
> (As a side-note, let’s not forget Zotonic is much older than Phoenix, and
> Zotonic has been doing things such as real-time client/server communication
> before Phoenix existed, let alone added Channels.)
>
> 4. Phoenix is well-designed and properly *decoupled* (Plug for HTTP, Ecto
> for databases and Contexts for domain logic). The same cannot not always be
> said of Zotonic. So switching over to Phoenix will result in smaller
> Zotonic components written in higher-quality code.
>
> 5. Most web development on the Beam VM is happening in Elixir: if you need
> authentication, JSON-LD parsing etc., there are much more likely to be
> up-to-date, well-maintained and documented Elixir *packages available* on
> Hex.pm than a single Erlang one. It therefore makes sense to integrate with
> the Elixir ecosystem.

Agreed. My company normally builds custom products for customers. I like
to say that Elixir/Phoenix has the ability to build all parts of the
application on one platform: public website, admin CRUD, mobile API,
real-time messaging, 3rd party API integration. In reality, a part
that's of that story that is rough is making it easy for non-technical
customers to update the public facing pages. We can build custom CMS
functionality, but it is better to to call on a component like Zotonic.

> Cheers,
> David

Cheers,
Jake

> Op dinsdag 3 oktober 2017 04:23:11 UTC+2 schreef Jake Morrison:
> >
> > On Mon, Oct 02, 2017 at 10:39:04AM +0000, Marc Worrell wrote:
> > >
> > > > On 2 Oct 2017, at 02:19, Jake Morrison <ja...@cogini.com <javascript:>>
Reply all
Reply to author
Forward
0 new messages