
Lovely Week with Elixir - sgadimbayli
https://www.ramblingcode.dev/posts/lovely_week_with_elixir/
======
biggestlou
I learned Elixir a few weeks ago as a quarantine self-improvement project and
pretty much loved it. There are some warts, as in any language. As someone
who's primarily worked in Go and Java in the past and has also been learning
Rust I don't super love the optional typing thing, and I end up missing
higher-level data constructs like interfaces and traits.

But there are some great language features, like guards and pattern matching,
that are hard to give up when you go back to other languages.

Plus it's great to have OTP goodies like GenServer at your fingertips if you
run into performance bottlenecks (which you may not!). The OTP APIs are a bit
weird coming from other languages but not too bad.

Other things I've liked:

1\. Ecto is simply the best DB library I've encountered in any language. I'd
almost recommend learning Elixir just to be able to use Ecto.

2\. Plug provides great HTTP ergonomics highly reminiscent of Go's context-
based middleware approach. Having direct access to the full request/response
lifecycle is a win.

3\. Phoenix is nice because it's essentially just Plug with some convenient
helpers on top. Strikes a really nice balance between configuration and
convention by letting you use only what you need. Haven't tried LiveView as
I'd prefer to handcraft my own JS but probably worth a shot.

4\. Absinthe is the best GraphQL framework I've encountered after many others
in other languages left me completely cold.

~~~
skeletal88
Interesting. I really like Python and SqlAlchemy. Changing objects in the
database via changesets and applying them on top of eachother feels kinda
alien, when I can't do object.property = something.

The thing that confuses me most about Phoenix and Elixir is how do I actually
deploy the application to production? I have my own server where I can run
whatever I want (running Ubuntu), so what do I have to do to get my Phoenix
application working there? How do I get my code running as a systemd service?

~~~
ch4s3
1\. It's a functional thing, it's quite nice after you use it for a bit, and
really powerful because you can use it for any data, and not just when working
with a DB.

2\. There are several ways. You can use releases [1]; copy the code to the
box, run mix release, then ./app start, and point whatever you want to that
process. If you're running phoenix you could always compile it on the box and
just run mix phx.server. I wouldn't do that though. You could also use a tool
like distillery[2] which is kind of like releases. There is another more
esoteric option where you build locally without the runtime, but I wouldn't
recommend that.

[1] [https://elixir-lang.org/getting-started/mix-otp/config-
and-r...](https://elixir-lang.org/getting-started/mix-otp/config-and-
releases.html)

[2]
[https://hexdocs.pm/distillery/tooling/cli.html](https://hexdocs.pm/distillery/tooling/cli.html)

~~~
joeyspn
+1 for distillery, very convenient...

[https://github.com/bitwalker/distillery](https://github.com/bitwalker/distillery)

~~~
losvedir
Once `mix release` was added natively to Elixir in 1.9, I haven't found the
need to use distillery anymore. Is there still a use case?

~~~
ch4s3
Distillery has 2 strong use cases; it has config providers which allow for a
lot of config flexibility and it can support hot code upgrades.

------
ashton314
The BEAM is a huge win: having lightweight threads means you can often do away
with things like Redis for job queues and PubSub stuff. I love this answer on
StackOverflow by Elixir's creator:

[https://stackoverflow.com/questions/32085258/how-can-i-
sched...](https://stackoverflow.com/questions/32085258/how-can-i-schedule-
code-to-run-every-few-hours-in-elixir-or-phoenix-framework?rq=1)

So simple. Something that would require a job queue and a job runner fades
away into a piece of the OTP application tree. When it crashes, it will even
come right back up!

Phoenix feels a little too heavyweight for really small projects—maybe I'm
spoiled having used Mojolicious's [0] single-file web servers. (Example on the
linked page.) But for anything slightly larger, Phoenix scales _really_ well.
I work on a decently-large application in Phoenix for work and it's been an
absolute joy to work with this langauge.

Typing could be better. Though, Dialyzer does a decent job of catching type
errors. That's saved my neck on more than one occasion.

[0]: [https://mojolicious.org/](https://mojolicious.org/)

~~~
PascalW
I don't really understand this sentiment of not needing a queue system. This
is not much different from spawning a thread in Java to delay the email
sending.

For any serious application you want a job like that to be persisted so you
can guarantee it runs even if your application is restarted.

I know that Erlang/Elixir is designed for stateful applications and if you
have a cluster and do hot deploys this is less of a problem, but who does
that? Most Elixir applications I've seen are deployed as stateless systems
just like any Ruby, Python, Node etc systems.

~~~
polmuz
Having a queue means you have a distributed system. How do you handle network
problems, errors/retries, back pressure? OTP has excellent idiomatic tools for
all that and more.

~~~
jeremyjh
Elixir developers who need a queue generally reach for Rabbit (which any
language can use), or something backed in a database like rihanna[1] or
honeydew[2]. Rolling your own distributed system is very much a last resort,
and despite its excellent concurrency characteristics the BEAM still lacks
basics such as a battle-tested raft implementation.

[1][https://github.com/samsondav/rihanna](https://github.com/samsondav/rihanna)
[2][https://github.com/koudelka/honeydew](https://github.com/koudelka/honeydew)

~~~
zambal
> and despite its excellent concurrency characteristics the BEAM still lacks
> basics such as a battle-tested raft implementation.

A couple of years ago the RabbitMQ team has published a raft library[1] which
they use in their implementation of persistent queues. It has a flexible API
and implementing your own state machines is quite straightforward, as it
follows the OTP gen_* behaviour paradigm.

And by now, I'd say it's pretty well battle-tested.

[1] [https://github.com/rabbitmq/ra](https://github.com/rabbitmq/ra)

~~~
jeremyjh
I didn’t know about that - thank you for pointing me at it!

------
ninjakeyboard
Elixir is decent and I've worked with it a fair amount in production
systems... Mostly Rubyists seem to really click with it. And ruby idioms are
all over it - you can taste its history and proximity to ruby's ecosystem. As
a scala dev that ended up working with elixir for a couple years, my opinion
is that a typesafe elixir-like language would really bring BEAM back into the
mainstream. Akka is alright but it's shoehorned onto the JVM. BEAM is good as
long as you don't need to do heavy computation, but lack of type-safety (need
to use dialyzer?) means that shit breaks in prod that the compiler would have
caught. And yes, you can mitigate this with boatloads of testing and data-
validations with ecto or whatever. But every time we broke shit that a
compiler would have caught I cringed.

It's a great path for rubyists to move to Elixir/BEAM and every rubyist should
give it a whirl! I'm back working on scala and akka.

~~~
Scramblejams
The older I get the grumpier runtime errors make me.

I want ReasonML (language!) and Erlang (OTP!) to have a baby, and I want it
birthed by the Go runtime. (Go? Yeah, Go. I don't love the language, but I am
a lover of low latency and garbage collection, what can I say?) Yes, there's
Gleam, but if something's based on BEAM, the throughput generally won't
impress. :-( Would seem a shame to do all that static typing, and then not
reap the speed benefits.

Relatedly, I think there's a sweet spot for a language that accepts mutability
inside of actors, but only allows immutable objects to be sent as messages,
with an escape hatch available if needed. (Pony explored this space, would
love to see it evolve.) Combine that with OTP for happy-path programming, and
an ML so you catch most of your errors at compile time, and you could end up
with great throughput, low latency and great ergonomics, all at the same time.

~~~
lpil
> but if something's based on BEAM, the throughput generally won't impress

I'm not sure where you're getting that from- that's typically the area it does
well. It's bad at number crunching, but you if the work is IO bound (say, like
a web application backend) it offers consistently low latency with high
throughput.

~~~
Scramblejams
We're defining throughput differently. I'm talking about CPU utilization, i.e.
non-IO-bounded work. Sorry for the ambiguity.

------
namelosw
Elixir and Phoenix are living proof that functional programming can be easy -
most of the time you just play with struct and functions, that's basically it.
No need to pay attention to monads and type classes.

On the other hand, it also reflects functional programming is also more
straightforward than Object-oriented programming because it's more objective
to just model the data, than modeling the data and procedures at the same
time. If you have two people writing the same thing, there's a much larger
chance they'll yield similar or identical results.

------
mostlysimilar
I love Elixir. Phoenix makes web development a pleasure and LiveView is even
more exciting.

I would love to find a job doing it.

~~~
ketzo
Dude, LiveView is _wild_. It feels kind of magical, and I think people are
gonna start adopting slowly, then all at once.

There's an awesome blog post on their website. where Chris McCord, creator of
Phoenix, builds a real-time Twitter clone in 15 minutes.

[https://www.phoenixframework.org/blog/build-a-real-time-
twit...](https://www.phoenixframework.org/blog/build-a-real-time-twitter-
clone-in-15-minutes-with-live-view-and-phoenix-1-5)

~~~
heipei
I've been watching Elixir/Phoenix/LiveView from the sidelines, reading just
enough to salivate a little but still left with the feeling that my use-cases
wouldn't be adequately covered by it. Which kind of SPAs wouldn't work well in
LiveView? I'm working on an app in Ember right now where a lot of data is
fetched by the client asynchronously and then either showed once its fetched
or only when the user pushes a button. How would the latter be possible with
LiveView? Can you push data to the client that's only show on client-side
interaction? Do I still need a client->server->client roundtrip to toggle a
"visible" flag to show said data? I just don't understand how "smart" the
client side of LiveView is.

~~~
dnautics
The spas that won't work are the ones that need to keep state while offline.
Everything else works pretty fantastic, and arguably better than most spas
which need to do heavyweight xhr Json or grpc calls, though if you can have a
persistent grpc connection over websocket you might be competitive
performance-wise.

------
crusso
If you're interested in using Elixir, jump right into Phoenix with LiveView.
It is fantastic for prototyping new tools. Once you learn the basics of
LiveView, it's ridiculously easy to create the web UI that interacts with your
Elixir back-end.

For a while I was using Phoenix<>Elm as my stack and I enjoy programming in
Elm. But there's a lot of boilerplate you have to tediously connect for every
input and output on both sides of the server and client.

LiveView eliminates all that boilerplate by letting you write templates in
Elixir that are macro-compiled to javascript. Getting rid of that boilerplate
eliminates time writing it as well as time debugging the extra complexity that
boilerplate introduces.

~~~
mahaqmi
I really hope there's a book covering more in depth on how to use LiveView. Im
a little bit of a noob in programming and mostly learn using book for the
first few steps. A lot of my coworker asking me to learn through docs as it
seems to be more "full" but I found it's a bit steep learning with it compared
to book that usually hold your hand through each concept. This is how I learnt
Go web programming about 8 months ago.

~~~
gstipi
Have a look at the free Phoenix LiveView course by Pragmatic Studio:
[https://pragmaticstudio.com/phoenix-
liveview](https://pragmaticstudio.com/phoenix-liveview) (I'm not affiliated
with them).

The first six of eventually 15 lessons are already available and they really
helped me grasp the basics. I've already implemented a few small tools using
LiveView - it's a real breath of fresh air!

------
ketzo
Started a little CRUD-app project in Phoenix (Ruby on Rails to Elixir's Ruby),
and my expectations have been totally surpassed. It's pretty amazing.

Working with Elixir is really cool, too, coming from C++ & JS backgrounds.
Pattern matching feels like a programming technique from the future.

------
adamzapasnik
Another person who liked Elixir, cool :)

Btw. If anyone is interested, I'm working on prettier plugin for html l?eex
files. Probably gonna publish it next week.

~~~
udfalkso
That sounds lovely. Thanks for building that! Followed you on twitter, pls let
me know when it's live.

------
fredwu
I wrote two blog posts before on Elixir:

The first piece is longer, on my journey learning Elixir and building machine
learning libraries.

[https://fredwu.me/blog/2016-07-24-i-accidentally-some-
machin...](https://fredwu.me/blog/2016-07-24-i-accidentally-some-machine-
learning-my-story-of/)

The second piece is shorter, on Elixir’s functional aspect and how doctest
changes the way I code.

[https://fredwu.me/blog/2017-08-07-elixir-and-doctest-help-
wr...](https://fredwu.me/blog/2017-08-07-elixir-and-doctest-help-writing-
better-programs/)

------
aloukissas
The only downside I've found with Elixir is that because of the language and
runtime internals, it doesn't really lend itself to power serverless/lambda
functions (like Python, Ruby, Go, etc).

------
ldd
I had an excellent week with Elixir building a really silly game:

[https://hn.lddstudios.com/](https://hn.lddstudios.com/)

MIT Licensed. Source:

[https://github.com/ldd/hn_comments_game](https://github.com/ldd/hn_comments_game)

~~~
sgadimbayli
Awesome! If you are up for reviewing each other's code, ping me!

------
aloukissas
Welcome to the λ-side! We've been using Elixir and loving it for 3+ years.

------
peruvian
I really like Elixir and Phoenix. I just wish I had more reasons to use them!

------
sjm
I built the API for a side project in Elixir/Phoenix a couple years ago making
use of Phoenix WebSockets, and it was truly mindblowing how much you could get
done with such a little amount of code.

------
jonnycat
Like the author, I'm really truly loving Elixir. I recently wrote up some of
my experiences with Elixir/Phoenix coming from a Ruby/Rails perspective -
[https://medium.com/swlh/3-months-with-elixir-
phoenix-2810f65...](https://medium.com/swlh/3-months-with-elixir-
phoenix-2810f653f887).

Curiously, unlike most others here, I'm not completely loving Ecto. I
appreciate the philosophy and get changesets, but I'm finding the query syntax
clumsy.

------
jetpackjoe
I got really excited about discovering a new progamming language, Phyton, for
a second... but after some searching, I think that's just a typo

~~~
sgadimbayli
thanks!

------
pmarreck
Elixir: So good that your team simply won’t believe your claims

[https://ekarak.com/2020/05/16/of-elixir-phoenix-and-
analogie...](https://ekarak.com/2020/05/16/of-elixir-phoenix-and-analogies-to-
the-prime-directive/)

------
throwaway286
The job market for Elixir is pretty small. Sure, there are a couple of people
here responding with specific listings, but still. I was hoping it would have
ramped up by now but it seems that it's going to stay a niche player.

~~~
pythonaut_16
I think it's healthy but small, and growing.

------
flowers111
Looks like elixir is gaining more and more traction :)

------
Thaxll
The fact that it's a dynamic language make problems similar to Node / Python,
can't dev serious backend services without a strongly type language. Not
saying you can't, but you will have a lot of issues overtime that would have
been catch at compile time.

~~~
yesco
Having used all three in backend systems, I definitely disagree that they have
the same problems. Elixir is strongly typed but lacks static typing, in
exchange it has a powerful pattern matching system that more than makes up for
this problem in my experience.

But fundamentally the issues caused by lacking static typing is different from
the problems caused by being weakly typed like python and node systems are.

~~~
throwaway894345
Python is strongly typed. I fully believe that Elixir lacks the same problems,
but not because of strong vs weak. If I had to guess, I would put think that
it's because Python code is more likely to be mutable than Elixir, but that's
just a guess.

