r/elixir • • Jul 15 '20

The Elixir Learning Experience

Post image
276 Upvotes

35 comments sorted by

9

u/BigBeruboy Jul 15 '20

I’m a bit confused on the purpose of ETS. I just started to learn about Elixir, and I’m struggling to understand why it’s such a nice feature. Nowadays, we can just whip up a reddis store with docker and make it work. Could someone help me understand why it’s such a nice thing to have?

9

u/marth141 Jul 15 '20

@9:12 through 11:25

Show casing an ETS table handling random ass queries.

This video sold me on ETS.

https://youtu.be/8mXqxBBvNdk?t=552

2

u/[deleted] Jul 15 '20

This is a great talk. Thanks for sharing

23

u/webdevpassion Jul 15 '20 edited Jul 15 '20

One of the main benefits of ETS is that it provides redis-like functionality in Elixir. No need to bring in another technology written in a separate language. The less external tech you have to manage, deploy, monitor, the simpler your application becomes as a whole. You have the benefit of having your application’s dependencies in the same language as your application.

Of course, ETS can’t match redis on feature parity but most applications don’t need every ounce of reddis’ feature suite and can get by with ETS before bringing in redis

7

u/ClikeX Jul 15 '20

This. You probably already have a database to maintain. Add Redis, and that's another thing to maintain. Every thing we add is another thing to keep track of and maintain on top of your application.

4

u/BigBeruboy Jul 15 '20

Alright. It does male sense. Thanks a lot! But in a multi node architecutre (you dockerize your app 2-3 times) is there a way to distribute the ets storage?

4

u/aseigo Jul 15 '20

mnesia is one way, though it is not a silver bullet, it is very handy.

it does really depend on what you want or need to do with redis, however. it is used in various ways.

as a simple cache to lower latency, it is often nice to keep those caches close to the app .. in process even .. lowest latency possible, and we tend to have ample RAM for this these days.

but there are many optipns out there, ranging from the shards library to phoenix pubsub to broadway.. lots of libs that provide functionality i have seen redis (ab)used for, some of which build on ets or use it in some way internal.

2

u/[deleted] Jul 15 '20

Forgive me, I’m subbed here but haven’t used Elixir in a while and never used ETS. Is it possible to access ETS from other languages or only Erlang/Elixir? If not that seems like it could be a benefit of Redis, should you need to do that.

0

u/[deleted] Jul 15 '20

[deleted]

2

u/BigBeruboy Jul 15 '20

Ok ok, it does make sense! Thanks a lot

6

u/Probotect0r Jul 15 '20

I am working my way through Elixir in Action, after being sold by Sasa's talk "Soul of Erlang and Elixir", and am currently at panel 3. It's so different from traditional languages, but so awesome.

3

u/marth141 Jul 15 '20

Elixir in action comes so highly recommended! I strongly encourage to go with it because the results I have seen from friends who have dove deep into it are extraordinary. Fucking slay it man!

4

u/kickinespresso Jul 15 '20

Woah. Now I'm trying to figure out how to work ETS into my next project.

4

u/marth141 Jul 15 '20 edited Jul 15 '20

So far, I'm using ETS to cache data from a "Salesforce" like CRM that doesn't have enough reporting capability.

The Elixir application is using a Task Async Stream to paginate it's way through the CRMs records, and ETS behaves as a storage. GenServers that are "Collectors" for the CRMs record types handle initializing the ETS tables, then get the records, then inserts into ETS.

The GenServers then use ex2ms to help build queries for ETS match specifications.

Then, I'm using ETS to store the values of particular metrics that are being reported on. This way when someone is requesting the web page that is displaying those metrics, they're already calculated and stored in ETS and not being calculated when the page is loading. Makes for very quick page load times.

0

u/[deleted] Jul 18 '20

[deleted]

1

u/marth141 Jul 18 '20

Yeah ETS is an in memory database that only exists while Elixir is running. Evadne Wu expressed that she felt like ETS is an escape hatch from the immutable nature of Elixir.

You have to load things into ETS like { id, thing_to_store }

And it can have any number of things to store. But it must have an id of some sort.

2

u/qqwy Jul 15 '20

You're missing a final one at the bottom with "writing macros that erite macros that write macros that write... " :D

3

u/marth141 Jul 15 '20

Dave Thomas said, "Never use a macro where you could have used a function!" Or something like that haha.

but you got me gotta make a macro

2

u/noscreenname Jul 15 '20

Then learning that the ecosystem is ... Inexistent 😰

1

u/marth141 Jul 15 '20

I have plans to make some learning stuff on YouTube once I'm much more seasoned.

Until then, I found a major amount of help with https://codestool.coding-gnome.com/courses/elixir-for-programmers

https://online.pragmaticstudio.com/ has some good material as well!

Check out discords and slacks as well :)!

5

u/nathan_long Jul 16 '20

the ecosystem is ... Inexistent

I'm not sure what you mean there. I see:

And that doesn't even cover everything.

What do you feel is missing?

3

u/noscreenname Jul 16 '20

I'm running elixir in production since 3 years, so I'm probably one of the 500+ companies. What I mean, is most of the external libs are outdated and have very few commiters.

61

u/Schrockwell Jul 15 '20

wishing you had the pipe operator in every language

19

u/mypetocean Jul 15 '20

Ehem — the pipe operator, pattern matching, and the guard clause syntax (if not function overloading).

5

u/Schrockwell Jul 15 '20

The functional holy trinity!

5

u/[deleted] Jul 15 '20

Binary matching is also really sweet

6

u/willhig Jul 15 '20

I had to go back to typescript for a gig and kept having moments like “okay, then pipe this into… wait… dammit…”

3

u/jonas_h Jul 15 '20

That such a simple thing can have such a big impact.

1

u/[deleted] Jul 15 '20

[removed] — view removed comment

1

u/marcio0 Jul 21 '20

this is great!

5

u/willhig Jul 15 '20

MOAR ELIXR MEMES pls

2

u/deadidentity Jul 15 '20

This feels about right :)

2

u/sanjibukai Jul 15 '20

I can relate to this!

2

u/Embarrassed-Box-3380 Jan 05 '25

This is real, i literally just completed the full cycle like 2 days ago.

2

u/3dB Jul 15 '20

I'm currently at the third panel. Decided I wanted to learn the language and started doing some crypto challenges in it. I was having a difficult time with it until I learned the details of pattern matching against binaries. Now I'm hooked for life.

5

u/lytedev Jul 15 '20

Binary pattern matching is seriously so cool.

1

u/rhbvkleef Jul 16 '20

ETS? Pfff. Lets go for mnesia!