DEV Community

mirko
mirko

Posted on • Originally published at owlcode.eu

Elm, an alternative to Javascript

What is Elm ?

Elm is a pure functional programming language with a strong type system. It is Open Source (released under BSD-3-Clause license) and this year is 10 years old.

The current version is 0.19.1 and it is surrounded by an active community.

Elm is "domain-specific", its goal is to help you building front-end web applications.
The compiler produces optimized Javascript code to run into the browser. It supports developer with a detailed and more clear as possible output to help resolve errors.

An example of compiler output:

naming error
Line 44, Column 12
I cannot find a `Timestamp` type:

44|       ts : Timestamp,
               ^^^^^^^^^
These names seem close though:

    Timstamp
    Time.Zone
    Task.Task
    Time.Month

Hint: Read <https://elm-lang.org/0.19.1/imports> to see how `import`
declarations work in Elm.
Enter fullscreen mode Exit fullscreen mode

There is an online editor, named Ellie, to play with the language without the need to install anything on your machine.
Ellie permits to install dependencies for your code, so you can prototype an entire project with it.

Applications in Elm follow the TEA (The Elm Architecture), an architectural pattern based on the following concepts:

  • Model: the state of the application.
  • View: transforms model into HTML code.
  • Update: updates the model intercepting messages which came from the user interaction with the view.

Why Elm ?

I started using Elm because I wanted to experience with the functional paradigm.
I tried it using Javascript, but its multi-paradigm nature didn't help me in having a focused functional experience, so I decided to try with an only-functional language and I discovered Elm, described as a good first step into the functional world.

To take practice with Elm I implemented a tiny project ts-converter: a browser extension to translate timestamps into human readable dates.
Ts-converter is released as a libre software under GPLv3 license.

Top comments (4)

Collapse
 
leob profile image
leob • Edited

But is it a serious alternative for something like React? (with JS or TS, obviously)

It just seems incredibly niche ... I googled a bit and came across this insightful post, which says that if you want to use something else than JS/TS for frontend development then use Purescript rather than Elm:

reddit.com/r/javascript/comments/2...

The fact that someone who invested a lot of time in Elm is advising NOT to use it (but to use Purescript) is very telling, IMO.

I think if you choose something like Elm, rather than tried-but-true React/JS/TS, you'll have to be prepared to live on the cutting edge, spend a lot of time researching problems (and by "researching" I don't mean googling it on Stackoverflow), and frequently hit a very thick unyielding brick wall when you can't figure things out and there's nobody who has an answer.

React/JS has a huge community and ecosystem, which allows you to "google" yourself out of virtually any problem you can throw at it - there's always a way out or a way forward, I think that's the big point.

Collapse
 
mirkoperillo profile image
mirko

Your opinion is agreeable.

The point of my article is not something like "Hey you should use Elm for your next product", but it is "If you are interested having an experience with functional programming, give a chance to Elm that can be a good first step into this world" and the link you provided seems to confirm this idea.

Choosing a technology/language is always an hard work that cannot be generalized because depends to much to the context around the deciders.

Surely choose Elm as your flagship language needs a deep awareness, much more than taking a more "mainstream" solution like React/Angular/Vuejs.

Anyway some companies made this choice so it is not totally insane.

Collapse
 
lucamug profile image
lucamug

@leob, @mirkoperillo,

You can find a partial list of companies using Elm at github.com/lucamug/elm-companies/b...

Thread Thread
 
mirkoperillo profile image
mirko

Thank you @lucamug

a very interesting resource