dogweather

dogweather

Can anyone recommend books/courses/videos that use real-world Elixir? E.g.:

  • Idiomatic error handling design, whether it’s {ok/error, ...} or something else.
  • Uses specs as they “ought” to be, however that is.
  • Uses the various mechanisms for creating types such as @type, defstruct, and @enforce_keys.
  • Test-first coding generally, if that’s common.
  • Idiomatic module and function naming.
  • Use of keyword lists in function signatures.

(The resource or two I’ve purchased teach good architecture, apparently, but are not idiomatic, unfortunately.)

Showing Posts 1 to 10

Nefcairon

Nefcairon

Sadly you haven’t got any answers. I cannot give you any either, sorry.

To be honest, though having bought many Elixir books, I haven’t read half of them as the last months I get slowly “detached” from Elixir because of the fact that the ressources always lack at least one of this aspects, if not many.

If I continue learning Elixir, I want to learn it as “right” as possible. Haven’t wrote any elixir code for two months now. It’s a pity, as the language is great and this forum is great, too. I hope something brings my enthusiasm back I haven’t had since rails 15 years ago.

wanton7

wanton7

By “keyword lists in function signatures” do you mean typespec for keyword lists? You don’t really need to use typespecs at all if you don’t want to. Typespec link I provided should have info on it. Elixir HexDocs is your friend.

dimitarvp

dimitarvp

This is a pretty broad and rather strange statement.

The way out of something like this is to open-source something and ask for reviews IMO. I feel that most Elixir books authors think that everybody has to code in their own style, or they aren’t focusing on teaching coding style and what they might feel is an “idiomatic” Elixir.

lucaong

lucaong

My suggestion, if you feel you know Elixir well, but you want to step up your practical Elixir coding skills, would be to read the codebase of some quality open-source projects. The source code of Elixir core library is a great place to start, as well as delving into libraries that you use, and possibly contributing to them.

Subjective opinion here: I would not stress too much about what is idiomatic or not, but rather develop a sense for which codebases are easier to navigate and why. Reading other people’s code helps in this respect, because we always approach it as “beginners” with little context. As developers, I think we focus too much on code style on a superficial level (stuff that linters can enforce) and too little on deeper aspects of what increases/decreases cognitive load.

dogweather

dogweather OP

I just mean using keyword lists as function parameters. E.g., this mentions it:

keyword lists [are] the default mechanism for passing options to functions in Elixir

But the books & instructional materials I’ve read so far haven’t made use of this. And I think I might have had some trouble pattern matching with keyword lists when I last tried it…

dimitarvp

dimitarvp

Absolutely. Main focus should be readability and very quick onboarding of a stranger. Some people also focus on as little coding lines as possible which is IMO also a wrong metric.

wanton7

wanton7

Yes it should be explained better in that document. I haven’t had this problem because what I usually do is look at code made by core team like Ecto as example. I think it would be very helpful for future users if you created issue for this to GitHub - elixir-lang/elixir: Elixir is a dynamic, functional language for building scalable and maintainable applications · GitHub repo, that keyword list function options need to be explained better.

Ecto uses parameter named opts that is a keyword list for lot of its functions to provider optional options. Maybe these will help you show how it’s used.
https://medium.com/@brucepomeroy/accepting-optional-options-in-elixir-65e7eaed11ac
https://github.com/elixir-ecto/ecto/blob/master/lib/ecto/changeset.ex#L2441

dogweather

dogweather OP

Excellent, thanks. Personally, I’m skeptical about this kind of API design because it enables silent failures and isn’t self-documenting.

wanton7

wanton7

Yes if you are going to use keyword list parameters you should document usage properly. API made by Elixir core team usually has excellent documentation. I haven’t usually seen this level of API documentation in other languages I’ve used. As you can see from that check_constraint function ecto/lib/ecto/changeset.ex at b7c4dbd67d59f976fab021ca8164e10f92453010 · elixir-ecto/ecto · GitHub

You can directly create documentation from code comments here is example for that function Ecto.Changeset — Ecto v3.14.0

I think it’s kind of idiomatic Elixir to write good documentation. Here is some info about how to write documentation Writing documentation — Elixir v1.20.2

Maartz

Maartz

I’ve bought this one and since the beginning we use defstruct or @enforce_keys etc.

Functionnal web dev with Elixir, OTP and Phoenix
It’s a very good book.

After, for the tests suite, I’m practicing it in Phoenix Programming 1.4. For the rest, I can’t say.

I recall having used defdelegate in Dave Thomas course on Elixir, where you build a hangman, people says that he wrote idiomatic Elixir code, and we write test all along.

Where Next? Top

Trending in Chat/Questions Top

Other Trending Topics Top

KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews