Just me or are most blog posts and youtube tutorials outdated?

That’s strange, since this is what’s written about it:

https://hexdocs.pm/elixir/Supervisor.Spec.html

NOTE: The functions in this module are deprecated and they do not work with the module-based child specs introduced in Elixir v1.5.

Yes, I saw the note on the site. I think the wording might be misleading in that it makes it seem like this no longer works in general. It does in fact work and pulling the code from the repository (https://github.com/tensor-programming/Elixir-4/, not the one listed in the YouTube description, this YouTube channel and organization is run really badly) you can run it without any issue with v1.6.

A friend once told me that he thought the abstractions introduced for supervisor specs and whatnot in Elixir were a bad idea. I think I brushed it off and said that supervisor specs suck so they should be fixed, but he argued that people would end up not knowing what it is they were doing since everything is hidden away too much and maybe he was right. If we weren’t trying to fix this by making it look like magic, people would learn the ugly way but at least know exactly how it worked.

2 Likes

Hmm, I really hope Elixir is not going down the Java path, with a lot of deprecated code that will still work ten years from now.

On one hand I agree, but just in the previous post I argued for using (and supporting) something that is ~21 years old. The reason is that this specific issue wouldn’t exist if people knew what the supervisor spec was actually generating (previously a tuple with a specification for what a child is and nowadays a map with the same information, with reasonable keys that describe the specification).

Yes, I definitely agree with that. Migrating projects to new version is in my experience very easy, many times it works with no changes at all.

I believe the problem here is that the material does get outdated, since some techniques recommended by learning resources are deprecated.

As I’m just working on Elixir in Action update, I’ve felt this myself. In just three releases, there have been some additions which forced me to do a thorough rewrite of supervisor chapters. In just three versions (1.4-1.6) we’ve got the Registry, new child specs, and DynamicSupervisor, which completely changes the way we manage supervision trees. The old way still works, and that’s great. But I understand if people entering Elixir are frustrated to find that the techniques presented in the material are not recommended anymore.

Just to be clear, I’m happy to see how the language constantly moves forward, and I’m very excited about the mentioned extensions to the language. I was personally advocating the inclusion of Registry for a long time. I definitely hope Elixir will keep that pace and move forward. But the consequence is that the learning material will also grow outdated to some extent.

The best advice I can give to the people just learning Elixir is to start with the official learning guides, as these will always be up to date. And of course, reference docs are IMO very well written.

I agree! I’ve started working on EiA way back around 0.9, when we didn’t even have maps, and I’ve been constantly amazed how well organized and informative the changelog is. This made it very easy for me to migrate the content, as well as Elixir projects I’m working on.

5 Likes

That’s good to know. I will put your book on my reading list.

The main reason I think https://online.pragmaticstudio.com/courses/elixir/ is such an excellent course, is that they start building the program using only spawn and then replacing it with GenServer. You really understand the reason behind the abstractions.

As long as the reason behind the abstraction is clear, I don’t mind if there are different ways to do the same thing. The problem comes up when there seems to be a “wrong” way of doing something, which is usually what deprecated code tells us, and when there is no clear reason which one to use.

Java never seem to get enough of collections, and JavaScript has too many ways to create new objects, including the somewhat unnecessary class. With a given rationale behind each choice, I can make an intelligent decision what to use, and not having to rely on chance.

All code written in earlier Elixir versions should work on more recent Elixir versions. So even if a book was written for Elixir v1.3, everything should work on Elixir v1.5 or v1.6. You may get a deprecation warning but the warning will point you to the proper direction.

I agree it is misleading and in the latest iteration they can even be mixed, I believe. I will update it.

4 Likes

Having a simple function that validates its inputs and returns a data structure is hardly magic. It is pretty much the bread and butter of programming in Elixir.

Sometimes I get the impression people throw the word “magic” around as a quick way to disagree with something without actually describing why or without considering the list of pros and cons that go behind it. For example, when you say X is magic, it can be followed by an explanation that “it is a macro that rewrites the AST” or “it is macro that injects variables” or because “it is a function that relies on side-effects”. This allows everyone to judge how much complexity is actually involved, instead of hiding it all behind “magic”.

Anyway… :slight_smile: we need to remember that when Supervisor.Spec was added to Elixir, the only way to specify a supervision tree in OTP was by using tuples, like this:

{Registry, {Registry, :start_link, [...]}, :permanent, 5000, :worker, [Registry]}

This is not an acceptable API by any measure. A new developer wouldn’t understand what half of those things are, because we don’t even have key names. And most experienced developers would be unable to build such tuples without consulting the docs every time. And if you got something wrong, the error reports were less than ideal.

Since we didn’t want to rewrite supervisors, we had to wrap the validation and creation of those tuples, which led to Supervisor.Spec. Now that OTP itself has moved away from tuples, Elixir went back to mirroring OTP and now prefers the child specification to be specified as a map, but we didn’t have this option back then.

8 Likes

The idea wasn’t to just try to sweep it away. I presented why I thought this may have been harmful to some degree in the very post you quoted and it was also very clear in that very post that I agree with both sides of this:

I think I brushed it off and said that supervisor specs suck so they should be fixed, but he argued that people would end up not knowing what it is they were doing since everything is hidden away too much and maybe he was right.

That’s precisely the API you then go on to criticize and what I referred to in the post after:

The reason is that this specific issue wouldn’t exist if people knew what the supervisor spec was actually generating (previously a tuple with a specification for what a child is and nowadays a map with the same information, with reasonable keys that describe the specification).

If anything, I think I’ve highlighted the trade-offs of hiding the spec tuple behind a curtain, let’s say. It’s not magic, but it’s also something that’s occluded supervisor specs to a lot of people. If they knew the underlying structure of it they’d also understand the replacements and what they can always use under the hood when the replacements are changed/disappear/cause issues for them.

To be clear, I still think abstracting it was the way to go, but I definitely understand why my friend thought it was a bad idea.

2 Likes

Dave Thomas elixir course is the best one I’ve seen so far. I’m halfway through it and I wish there were more of this quality… it leaves out all the annoying fluff and 45 minutes of writing tests with 5 minutes of poorly explained coding. I wish he had more than one course, I’d buy them all.

2 Likes

He’s already started on his second one :003:

Please leave a review in that thread if you haven’t done so already :slight_smile:

5 Likes

This is one of the reasons I started my channel 3 months ago! Dozens of longer-form videos and not out of date.

I have nothing approaching Dave’s level of experience, but it’s a lot of free content and often inspired by actual projects.

8 Likes

I’ve been keeping an eye on your videos and watching alongside other stuff for a while now. I really like the idea of free video courses and you are really helping the Elixir community :slight_smile:

3 Likes

Watched some of your vids recently when I stumbled upon them on YouTube. I was wondering that there were only a few views, as the content is really great! Keep it up. :blush:

3 Likes

Every channel will start out small with only a few views, overtime as more people watch and like the video YouTube’s algo will recommend it to others interested in learning elixir :slight_smile:

1 Like