Fl4m3Ph03n1x

Fl4m3Ph03n1x

Learning Elixir, frst impressions ( plz don't kill me ! )

About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )

Hello all, this is my first post in this forum, so I apologize is something is off.
I am rather a direct person with strong opinions, but don’t be afraid of me, I don’t bite !

Recently I have been learning Elixir for a job offer ( yes, apparently you can find jobs using this thing! I mean, you have to sacrifice a virgin and a goat [ it can be a virgin goat ] to the Gods of Old and pray for 7 days, but hey, if it works it works right ? ) and I have been ramping up in my Elixir knowledge by watching as many conferences as possible.

I have a strong JS background where I do FP ( yes, it is possible ), and I got lured into this language becasue of it.

I have a lot of questions so I am giving this forum a chance!

Source

This 1 hour video covers the main aspects of Elixir and makes sure you have a lot of questions after. Suffice to say you won’t learn Elixir in 1 hour, but it is a good start I guess.

The following points summarize what I learned.

Elixir Facts

  • It has modules. Modules contain and organize functions, so it’s cool.
  • It has a ton of data types, most notably: Int, Float, String, Atom, Tuples ( arrays ), Lists, Dictionaries, etc.
  • Int type is not bounded. It has no maximum nor minimum value. If you ever had an overflow using Node ( like me ) you will really appreciate this feature.
  • Has a native pipe operator ! |> JS is being left behind :stuck_out_tongue:
  • Has native String concat operator <>
  • Has native List concat and diff operators ++`` and --
  • Has destructuring !
  • Functions can have the same name as long as their signature is different !
  • Has anonymous functions
  • Has no for loop constructor. WHHHATTATATAGGAHHAHAGATIhvgdjfsAVSGBZ
  • Creates child processes easily and sends messages between them easily as well

Elixir Cons

Not everything is nice with Elixir. It also has it’s technical shortcomings:

  • No partial application and no currying. This is something I would expect from a FP language ( like Haskell ) to natively support. Huge disappointment.
  • Currying and partial application via anonymous functions have a weird syntax. Yes, you can make a library to workaround this flaw, but the syntax you need to use is … weird at best: http://blog.patrikstorm.com/function-currying-in-elixir
  • Being functional, Elixir has an horrible API. Most of it’s native functions are data first, instead of data last ( a basic concept of FP languages ).
  • No Monads. Again very disappointing.

Elixir Weirdness ( aka, stuff you will eventually get used to )

  • No return statements
  • Elixir also has default values for parameters, but the syntax is anything but intuitive. (x // 1, y // 2), this signature is saying that the default value for x is 1 and for y is 2. For most people, this would be a comment…
  • It has a short syntax for functions ( like the arrow syntax for JS functions ) but it is super cryptic.

Overall opinion

I know I am just starting. But aside from the data types ( that are immutable by nature ) JS actually has better support for the functional paradigm than Elixir. The native API ( String API comes to mind ) was designed using data first instead of data last ( a most basic flaw in an FP language ) and using currying with partial application feels clunky as all hell when compared to JS. And there are no Monads either … I mean Swift is not a FP language and even it has the Maybe Monad. How disappointing.

I must say I expected more from a newly designed FP language. The support for currying and partial application is rather atrocious but I can live with it.

I still didn’t get into error handling, but from what I have seen, it is extremely imperative with good old try rescue blocks. It would appear that basic knowledge from Promises and Futures is missing.

Questions

Or perhaps I am missing something? Allow me to rephrase my noob rant in an organized manner:

  1. How does one use Monads in Elixir?
  2. Is it possible to use currying and partial application in Elixir using the function normal syntax, instead of the .(x).(y) syntax?
  3. Are there any libraries widely used and publicly available to for the use of currying and monads?
  4. Are there any libraries that improve upon the mistakes of the native API?
  5. Is there a version of NPM or Ruby Gems for Elixir ( I understand there is none so far ) ?

Please let me know if I missed something. I have only seen a a couple of conference videos, I may very well be missing something brutal.

Most Liked

joeerl

joeerl

Creator of Erlang - Fondly Remembered

The good thing about Elixir (and Erlang) lies in the concurrency - it’s all about creating parallel process and sending messages - and this (as Alan Kay has pointed out on numerous occasions) is the
essence of OO programming.

OO programming is all about objects. Objects are things that respond to messages (or should be) - to get an object to do something you send it a message - how it does it is totally irrelevant - think of objects as black boxes, to get them to do something you send them a message, they reply by sending a message back.

How they work is irrelevant - whether the code in the black box is functional or imperative is irrelevant - all that is important is that they do what they are supposed to do.

Unfortunately the first big OO language based on this model (smalltalk) talked about objects and messages but messages in smalltalk were not real messages but disguised synchronous function calls - this mistake was repeated in C++ and Java and the “idea” of OO programming morphed into some weird idea that
OO programming had something to do with the organisation of code into classes and methods.

Erlang and Elixir support the lightweight creation of millions of isolated processes - everything works by messaging between processes - the design of a system involves observing the concurrency you want in your application and mapping it onto processes.

A web server in Elixir for 10,000 users is not “one web server with 10,000 users” (like Apache or Jigsaw or all the rest) it’s “10,000 web servers with one user each” - this is a radicle departure from conventional practise.

The fact that Erlang/Elixir processes are described in a simple functional language is more or less an accident - they started off in a relational language (Prolog) and C-nodes (for example) can be written in ANY language - the important point about Elixir (and any BEAM) based machine is that the underlying VM can handle extremely large numbers of parallel processes.

For a long time I’ve said “Erlang is the only true OO language” (now I guess I can add Elixir).

The basis of OO programs are:

 - isolation between objects (we do this)
 - late binding (we decide what to do when a message arrives at a process)
 - polymorphism (all objects can respond to the same message, for example, you could
   think of sending a "print-yourself" message to any object and it would know how to do it)

Of lesser importance is

- division into classes and methods
- syntax
- the programming model (ie functional or imperative) 

Once we have split a system into large numbers of small communicating processes the rest is relatively easy - each process should be rather simple and do rather little wich makes
programming easy.

What Erlang (and Elixir) added to programming was the idea of the link. This was Mike Williams idea - this extends error handling over process boundaries and with links and process we have all we need to build supervision trees and so on.

Supervisors, gen_servers and all that jazz are just simple libraries that hide a bit of detail from the user - they are just built in a rather simple way with links and parallel processes.

Erlang was not designed as a FP language - but as a tool for building long-lived
fault-tolerant systems.

Central to fault-tolerance is the notion of remote error handling. If an entire machine fails the fault must be corrected on a DIFFERENT machine. It cannot be corrected locally because the local machine is dead.

This means that to program for fault-tolerance we need distribution and messaging to be easy to program - so basically any design for fault-tolerance will end up looking like Erlang.

The whole point of Erlang was to make it easy to program fault-tolerant systems, a side effect is that it’s also easy to program scalable systems.

The differentiator between Erlang and Elixir and “All the rest” is the concurrency and fault-tolerence mechanisms - it not about Monads and Syntax and whether it’s a pure FPL.

Now would you like to handle 10,000 users in a single thread using callbacks to emulate concurrency or would you like to make 10,000 concurrent processes, each of which is simple and has no callbacks.

Each process waits for a message that it is interested in then performs a computation and sleeps waiting for the next message.

I think a big problem in evangelising Erlang/Elixir is that you have to explain how having large numbers of parallel processes solving you problem helps. Since no other common languages support concurrency in any meaningful way the need for it is not understood.

“But I can do everything in callbacks in a single thread” they’ll say - and they do - and it is painfully difficult - and you ask “what happens if the callback gets into a loop or raises an exception” - if they don’t understand the question you’ll have some explaining to do - if they do understand the question then you can tell them that in a strange far off land where was a was to program concurrency that did not involve callbacks.

joeerl

joeerl

Creator of Erlang - Fondly Remembered

I guess I could shorten the previous posting.

Please don’t sell Elixir as an FPL - it’s not it’s a CPL (Concurrent Programming Language)

Don’t get into “my FPL is purer than yours” arguments. Don’t even think about talking about Monads. Change the subject.

“What’s a CPL?”
“You know, the kind of stuff the WhatsApp servers are written in …”

:slight_smile:

gregvaughn

gregvaughn

Very good replies so far, but I’d like to step back for a brief historical overview that might help frame how you view Elixir in relation to other languages you know.

It is fundamentally a “concurrency oriented” language. Joe Armstrong (co-creator of Erlang) has described Erlang as such. Those design forces are reflected deeply in the VM itself, and it’s a property all languages on the BEAM share. The original reason for Erlang’s existence is that Ericsson needed a language to meet specific business needs. Fault tolerance was high on the list. Fault tolerance led to supervision which needed isolated processes (and basically independently discovering the actor model). Isolated processes needed immutable data and first class functions and tail call optimization. Thus functional features fell out of more primordial concerns. All of this pre-dates the creation of Haskell.

If you’re one that thinks proper “functional programming” has to include monads and currying, etc., then mentally put Elixir in a different language category or else you’ll remain frustrated. We have alternative means of solving similar concerns. They’re not as theoretically pure, but in practice work out well.

Everything I’ve said before applies to any language on the BEAM, so now let’s speak to Elixir specifically. It differs from its parent language of Erlang by adding Lisp-style hygienic macros and Clojure-style protocols. It adds the pipe operator from the ML family of languages and intentionally puts the subject first to optimize pipe use. It offers a superficially Ruby-esque syntax in some places (and differs strongly in others). It adds web development style tooling in libraries/packages via hex and in building/compiling via mix. There’s more, but that’s a good first group of things to digest.

There’s more to be said about intangibles like community. I find it quite interesting that you worry enough to put “plz don’t kill me” in your subject, and I’m pleased to see in the replies no inclination to even consider doing that.

Welcome!

DevotionGeo

DevotionGeo

Haskel Programmer:


Elixir Programmer:

15
Post #8
dwahyudi

dwahyudi

You mistake Erlang and Elixir as ‘pure’ functional programming languages. They aren’t.

Erlang is not like Haskell.

Erlang was built in a business mindset to serve business goal which has to be achieved by making trade-offs. There are some aspects in functional programming paradigm that perfectly suites with business models they were after (reliability and concurrency). They took it, they used it, there you go, Erlang.

Haskell was built in an academic mindset to be used as academic purposes.

14
Post #2

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

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
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
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement