News for hackers. Stuff that matters.
Re:The BEAM Has Spoiled Me by grantjpowell on Saturday August 15, 2020 @08:18PM (#24173635)
The BEAM is great, but the Elixir language itself is really what spoiled me. After having written ruby for years, I really enjoy what the Elixir language has to offer. Pattern matching[0] and the pipe operator[1] eliminate a ton of intermediate variables. Functional programming took a while to get used to, but I'm really starting to like thinking immutably. Now that I'm more advanced in the language, I'm starting to get into the Lisp style hygienic (and unhygienic macros)[2]. The Elixir standard library is really well done, everything is consistent and well documented. Elixir language level built in libraries like ExUnit[3] and Embedded Elixir (EEx)[4] are very high quality. For me the BEAM is just the cherry on top, I really like the Elixir language itself!

[0] https://elixir-lang.org/getting-started/pattern-matching.htm...

[1] https://elixirschool.com/en/lessons/basics/pipe-operator/

[2] https://elixir-lang.org/getting-started/meta/macros.html

[3] https://hexdocs.pm/ex_unit/master/ExUnit.html

[4] https://hexdocs.pm/eex/EEx.html

Re:The BEAM Has Spoiled Me by Kaze404 on Saturday August 15, 2020 @09:36PM (#24174071)
The killer feature for me was the documentation. I got thrown into an Elixir application that uses Ecto and Phoenix and literally everything I ever had to do was documented and explained in Hexdocs.
Re:The BEAM Has Spoiled Me by OkayPhysicist on Sunday August 16, 2020 @03:23AM (#24175930)
Seriously, the Elixir documentation should be considered the gold standard. Almost everything is documented with exactly what kind of situations the library/module/function should be used for, combined with illustrative examples showing how it should be used.
Re:The BEAM Has Spoiled Me by conradfr on Sunday August 16, 2020 @08:26AM (#24177217)
IMHO many function docs could have more examples.

Especially for a dynamic language which uses tuples/maps for a lot of arguments.

Re:The BEAM Has Spoiled Me by pepesza on Sunday August 16, 2020 @07:39AM (#24176992)
Coming from Erlang to Elixir - I find Elixir docs lacking in both coverage and terseness.
Re:The BEAM Has Spoiled Me by yawboakye on Sunday August 16, 2020 @07:57AM (#24177076)
I could agree. Coming to Erlang from Elixir, I truly appreciate the simplicity and small size of the Erlang language. Making it possible to write exhaustive documentation. In fact, in Joe's book he defers a lot to the online docs/manual for in-depth treatment of a lot of topics.
Re:The BEAM Has Spoiled Me by strzibny on Sunday August 16, 2020 @10:10AM (#24177938)
While you might be right, I dislike the style of Erlang docs.
Re:The BEAM Has Spoiled Me by hazz99 on Saturday August 15, 2020 @10:33PM (#24174389)
I love Erlang/Elixir and want to use it more, but I just don’t have any good use cases for it! I don’t often make big concurrent back ends - maybe REST APIs, but that didn’t seem easy last time I tried.
Re:The BEAM Has Spoiled Me by OkayPhysicist on Sunday August 16, 2020 @03:26AM (#24175942)
Phoenix takes a little bit of reading to figure out (though the documentation is brilliant, and really easy to read). Once you understand how it works, though, creating an API is extremely straightforward. It's amazing.
Re:The BEAM Has Spoiled Me by hazz99 on Sunday August 16, 2020 @03:37AM (#24175981)
I just couldn’t get past ecto! It never seemed to “click” for me. Maybe I need to go back and learn it more in-depth, it sounds like it’ll be fantastic once I get the hang of it.
Re:The BEAM Has Spoiled Me by OkayPhysicist on Sunday August 16, 2020 @06:58AM (#24176801)
The trick to Ecto is that it serves as a separation between your data storage, and your data representation in your code. Basically, there're 3 parts.

The first part is your schema. It defines an Elixir struct that is your domain model of your data.

The second idea/part is the concept of a changeset. It represents a change you'd like to make to the data store, but haven't yet. These are composable, so you can bundle a bunch of changes into a single, atomic unit, which you then send to your repo. If any part fails, then the whole thing fails, no changes are made to the persisted data.

The last thing is migrations, which strictly speaking are optional, but a huge convience. They define how you'd like your database to be structured. The cool thing about them is that they define rollback operations automatically.

Once Ecto "clicks", it really becomes a strong selling point to the language as a whole. It makes working with persisted data super easy.

Re:The BEAM Has Spoiled Me by dnautics on Sunday August 16, 2020 @04:40AM (#24176238)
It's definitely not an orm, as it was stolen from c# linq.

Imo this is actually much better than an orm because it really hits home that the data in memory are stale as soon as you receive them because database transactions are explicit, and not hidden behind getters and setters.

ORMs can get you into trouble because they try really hard to hide the problem of distributed state and sources of truth.

Re:The BEAM Has Spoiled Me by hvis on Sunday August 16, 2020 @07:40AM (#24176993)
Coming from (the much-maligned) ActiveRecord, I wasn't really impressed.

It has this cute macro-based syntax, and that seems to inform even the "functional" API as well. Yet when you I wanted to do something just a bit more advanced like joining on an association whose name I don't know in advance (or, say, want to parameterize the function with), I had to resort to writing a macro myself and then eval-ing it an runtime.

Re:The BEAM Has Spoiled Me by oli_b on Sunday August 16, 2020 @04:00PM (#24180727)
I had the same experience, but now I'm wondering - is ActiveRecord much maligned? It is news to me. It handles simple stuff really well, takes a lot of the pain out of relationships, and doesn't prevent you reaching for SQL when required. I also haven't ever found a good replacement for AR migrations, which makes schema changes + keeping a record of those changes absolutely seamless. Are there some alternatives I should be investigating?
Re:The BEAM Has Spoiled Me by hvis on Monday August 17, 2020 @08:34AM (#24186595)
> is ActiveRecord much maligned?

Well, take the numerous articles extolling the virtues of Sequel, or DataMapper, or, related to the current discussion, Ecto itself. Like how expressive this stuff is. And how ActiveRecord creates a too huge API surface on models, and that that leads to bad design, etcetera. Now to mention the callbacks, which are admittedly problematic.

But then I try those aforementioned libs and see sharp corners like terrible argument validations (in case of Sequel) which lead to silently failing code, or actual hard limitations on what I can ask Ecto to do without resorting to meta-programming.

> I also haven't ever found a good replacement for AR migrations

IME, both Sequel and Ecto migrations are fairly serviceable. But neither provides the schema dumping feature that AR has. Which is pretty handy.

Re:The BEAM Has Spoiled Me by cultofmetatron on Sunday August 16, 2020 @07:31AM (#24176935)
For me ecto was a breath of fresh air. When I look at an ecto query, I'm never guessing about the output sql. It doesn't try to make relational queries look like objects. Often times I think, "how would I do this in sql" and there's usually a matching Ecto.Query operator that handles that.
Re:The BEAM Has Spoiled Me by lawn on Sunday August 16, 2020 @06:06AM (#24176588)
I can recommend the book "Programming Ecto". Previously I had only dabbled with ecto in the context of Phoenix, but it didn't really click for me either, but the book does a good job going through the different parts of Ecto and clearing up some of my confusion with it.
Re:The BEAM Has Spoiled Me by elcritch on Saturday August 15, 2020 @10:35PM (#24174401)
Phoenix takes a bit of learning, but it’s not too bad. It also has pretty decent generators to create JSON/rest endpoints.
Re:The BEAM Has Spoiled Me by arvinsim on Sunday August 16, 2020 @05:11AM (#24176363)
For me it’s job opportunities. In the USA, I think there seems to be enough jobs but globally, it is still sparse.
Re:The BEAM Has Spoiled Me by jefflombardjr on Saturday August 15, 2020 @08:42PM (#24173765)
Can you recommend any learning materials that were particularly useful to you?
Re:The BEAM Has Spoiled Me by AlchemistCamp on Sunday August 16, 2020 @12:16AM (#24175041)
For me personally, Programming Elixir and Programming Phoenix, from the Pragmatic Bookshelf, were both very useful.

Quite a few of my students have said great things about Phoenix in Action, from Manning, and it looks to me like a fantastic resource for beginners. Elixir in Action is also top-notch and will show you what's special about the BEAM.

Re:The BEAM Has Spoiled Me by bigbassroller on Sunday August 16, 2020 @05:47AM (#24176502)
To those out there learning from “Programming Phoenix”, although is the best resource for lay of the land of Phoenix, the content is getting out dated with the rise of auth generator and the context model has also changed a lil bit. It takes diligence in following along and referencing the documentation to not get stuck.

Great book though.

Re:The BEAM Has Spoiled Me by AlchemistCamp on Sunday August 16, 2020 @08:11PM (#24182504)
Anything written after 1.3 is almost completely applicable today.

The auth generator is just a new feature. Learning how the pieces work from the book is still worthwhile.

My advice if you want to avoid confusion as you're learning is to just use the same version of Phoenix the book does! (1.4 in this case)

After you go through it, you can follow the official upgrade guides in just a few minutes.

Re:The BEAM Has Spoiled Me by mercer on Monday August 17, 2020 @03:41AM (#24184938)
I'll add that learning how to roll your own auth with the book and /then/ using the auth generator is a great learning experience.
Re:The BEAM Has Spoiled Me by categorybooks on Sunday August 16, 2020 @10:37AM (#24178170)
What would you suggest as a more up-to-date alternative?
Re:The BEAM Has Spoiled Me by SmooL on Saturday August 15, 2020 @11:27PM (#24174732)
Honestly the docs themselves are excellent https://elixir-lang.org/getting-started/introduction.html
Re:The BEAM Has Spoiled Me by s3cur3 on Sunday August 16, 2020 @07:22AM (#24176894)
It’s the only language I’ve used where just going step by step through the official docs was enough to pick up the language. Took me maybe a day and a half.
Re:The BEAM Has Spoiled Me by atulatul on Sunday August 16, 2020 @12:08PM (#24178894)
Disclaimer: This is primarily about language... not BEAM as such. Also, links are inline.

I liked the book Programming Elixir 1.6 By (Pragmatic) Dave Thomas. Solved the exercises. Did not quite find use for macros. And I have not done any production projects.

The pragmatic studio has some courses for the space: elixir, OTP, LiveView, etc. and free tutorials. The quality is good. Simon Thomson's course on futurelearn was also good. https://pragmaticstudio.com/ and https://www.futurelearn.com/

A recurrent problem for me though has been to write an application. I used to write java's petclinic/petstore application when learning a framework, library, etc. Have not been able to do so with some other ecosystems... perhaps laziness, perhaps have not been able to answer why. And languages in isolation have not clicked for me much apart from maybe making me think in different ways.

Why does this Erlang/Elixir/BEAM interest me then? A colleague who talked highly of it... Then there's Joe, his talks, and Alan Kay's recommendation has Joe's thesis on recommended reading list: https://news.ycombinator.com/item?id=20653453

There is also Erlang Masterclass series 1,2,3 starting here: https://www.youtube.com/playlist?list=PLR812eVbehlwEArT3Bv3U...

Re:The BEAM Has Spoiled Me by jspash on Sunday August 16, 2020 @04:28AM (#24176192)
Without a doubt, this was one of the best courses I've done in any language. https://www.udemy.com/course/the-complete-elixir-and-phoenix...
Re:The BEAM Has Spoiled Me by searchableguy on Saturday August 15, 2020 @11:48PM (#24174873)