Alia

Alia

What were the most challenging tasks you faced and how did you solve them in Elixir?

Greetings Everyone!

Let’s discuss the challenges that we are facing in Elixir from start. Everyone can share his/her story according to their own. I love to hear your stories. :innocent:

Our topic is what are the most Challengeable task you face and how you solve it in elixir ??

Most Liked

dimitarvp

dimitarvp

Some of the challenges of Elixir I had to deal with more and more in the last years due to helping (or being in charge) with fairly busy systems where efficiency matters, are:

  • Taking into account process boundaries and what data gets copied from one process to another. This has led me to discussions during which I completely scrapped a nascent mini library I wrote and replaced it with a very thin layer over the :jobs Erlang library, for example.
  • Binary copying or referencing. Every now and then we have threads on this forum where people are puzzled with growing memory usage that does not go down and the reason is binaries with too many references pointing at them, 99% of the time. Hence the need to become friends with :binary.copy, or Jason.decode(text, strings: :copy) , or others.
  • The OTP machinery is amazing, though some things in the library ecosystem remain underdeveloped in terms of convenience and ease of use and terse code – e.g. when you need to monitor a process, or make sure it traps exits and its parent is aware of it, or have a GenServer worker branch outside of itself and its parent supervisor’s children to do a long-running task etc., the resulting code is just not readable, is boilerplate-y, and it reads like incantations We still need a more English-like DSL for OTP! (Though granted, that’s more like a usability complaint but I’ve seen people get confused when shown the current way these tasks are done. That’s important; stuff should be 100% intuitive.)
  • Even though I have no good ideas on how to improve upon that, I still feel Elixir projects have way too many files. :person_shrugging:

There are likely more but these are the ones that I got off the top of my head.

cjbottaro

cjbottaro

Problems (as a 10+ year Rails dev)…

  1. Maintainability in large codebases.
  2. Easily addressing things like n+1 queries while being DRY.
  3. Efficiency/scalability.

Solutions…

  1. A (soft) type system.
  2. Some semblance of interfaces.
  3. Separating dataloading from logic (Absinthe + Dataloader, aka Elixir’s GraphQL framework).
  4. Not having to deal with excessively inefficient frameworks.
  5. Actually good documentation. External and internal.
  6. A good VM (Google about Ruby GIL or threading model).

This is just scratching the surface. I honestly wished I kept some kind of journal for this.

cjbottaro

cjbottaro

The product I work on is a pretty big Rails app. There is no static analysis at all, no interfaces; it’s purely interpreted and your only saving grace is writing tests.

We’re slowly porting over some of our backend to Elixir (and even experimenting with some frontend stuff)… and just having a compiler is a major step up. Then Dialyzer is awesome on top of that! We’ve gotten to the point where we pretty much typespec everything, and the immediate feedback is incredible. I can’t wait to see where the set theoretic typing stuff goes.

We definitely use less DSLs in Elixir, but compile time checking of DSL usage is great!

HEEX validates your HTML, Absinthe validates so much of your GraphQL schema… all at compile time.

I think functional is easier than OO (especially Ruby OO). Tracing through our Ruby code is a nightmare. Objects create objects that create more objects. Classes inherit and mixin several modules, so we basically have multiple inheritance all over the place. There are no interfaces, so we have to traverse tons of files to find methods that raise "implement me". Or worse, modules that expect methods to be implemented, not in the class including it, but some other module that should be mixed into the base class. And lastly (not specific to Ruby), you have to think about which methods mutate state (instance vars). In Elixir, you have arguments and a return value (for the most part). It makes reading and tracing through code 10x easier, imo.

And also, the documentation system is fantastic. I find it both satisfying and fun to write documentation now. For a lot of pure functions, we write doctests. Contrast this to our Ruby codebase where no one likes writing docs… so there are none. Our CI system builds the Elixir docs and uploads them to a static site.

All this stuff adds up to better maintainability. In short: a compiler, type system, static analysis, no OO, and documentation system. All that with the benefits of a dynamically typed language. It’s like having your cake and eating it too!

Where Next?

Popular in Discussions Top

vans163
So useless benchmarks aside, Its possible to write a webserver that can serve 300k requests per second (perhaps more with optimizations)....
New
andre1sk
A big advantage to Elixir is all the distributed goodness but for many applications running on multiple nodes having integrated Etcd, Zoo...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New
mmmrrr
Just saw that dhh announced https://hotwire.dev/ Is it just me or is this essentially live view? :smiley: Although I like the “iFrame-e...
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
scouten
I’m looking for a host for the server part of a small (personal) side project that I’m working on. It’s currently written in Node.js and ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
sashaafm
Piggy backing a bit on @dvcrn topic BEAM optimization for functions with static return type?, I’ve been trying to understand in a deeper ...
New
Markusxmr
Since Drab has been developed for a while in the open, introducing the Liveview functionality in a way it happend appears to undermine th...
New

Other popular topics Top

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
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement