Some complaints about Elixir

Hi,

i am a beginner in Elixir. So far i have two main complains. Hoping i can get some advice on these.

  1. The compiler does not pick up enough compile time errors like Haskell or Scala does. In the end i experience more runtime errors. Perhaps there is nothing much i can do here because its not a strongly typed language? Will using @spec help?

  2. Have been trying out Phoenix and i dislike the fact that the DSL and the use of macros and meta-programming sometimes make things work like black-magic. Does this mean i have to learn the in/outs of meta-programming to understand things better?

2 Likes

Elixir is a dynamic language, so the compiler will not give you a lot with respect to types. If you use @spec the you can run Dialyzer/dialyxir to get type error checking.

More generally, Elixir and Erlang try to fail gracefully in production, which is a much broader and deeper topic that perhaps other folks can expand upon.

Yes, meta-programming is a bit of black magic. ELixir makes heavy use of macros, you’ll find them everywhere, but they’re more approachable than they appear at first. Thake a look at the guides here, and you’ll see how unless is a macro on top of if rather than a keyword.

Fortunately Phoenix is only a thin layer on top of standard mix projects. As you use it, you can start learning more about particular areas of interest.

1 Like

I don’t find that @spec helps with that many issues. For us, the only reason we use typespec is to act as lightweight documentation / readability. For a dynamic language, Elixir has a fairly advanced type system, so it isn’t always clear what a variable name user is.

I’ve heard this complaint about dynamic languages a lot recently (your timing is appropriate). I’m a pretty big tester and I find that tests (unit, integration and fuzz testing) solve most of these problems. Importantly, I don’t find that I have to write any additional tests in dynamic languages. I’m not writing type-specific tests (unless their’s some behavior / logic tied around type X or type Y). Plus, testing in a dynamic language is always easier / more efficient.

From the above, you can see that I think it’s a net gain. I write the same amount of / types of tests, but they are easier / faster to write. As a side effect of those tests, I feel most type issues happen to get resolved.

You know, not all programmers are the same. I think some programmers might need a compiler more than others (which isn’t a bad thing, there’s a billion factors…we’re not all going to be the same across all those factors). I do think you can train yourself to lean on a compiler less…maybe writing more focused functions, maybe naming things better, maybe writing more tests.

As for macros…I also started learning Elixir through Phoenix. I also hated the magic. I just slowly peeled it away. It’s like anything else, when you’re just starting, it’s a little overwhelming. I think you should learn the meta-programming stuff (because it’s powerful and useful), but you should do it on your own time. Spend what time you feel you need to to understand the magic, and, in the meantime, just accept it.

2 Likes

@kseg, what are you using for Fuzz testing with Elixir/Phoenix?

I would like to add that the main magic of Phoenix, in my opinion at least, is that there isn’t any. It is very introspectable, well-documented and easy to dive into the guts of if required.

Please elaborate on the parts that feel like a black box, because I am sure we will be able to explain it to you. And if the documentation is not clear enough, this is considered a bug in Elixir’s standards :smile:.

4 Likes

our own app-specific node clients. I should probably look at generalizing it, sorry.

1 Like

No worries! Throw a post up on the forum if you do!

Thank you all,

it is reassuring to hear from people who have gone down this path before me.
Great documentation is one of the good points that i like about Elixir.

The recent blackbox that frustrates me a bit is not Phoenix specifically
but ExUnit tag.
The documentation is helpful in how to use it and stuff but it still works
like black magic to me as in i know what it does but not how it does it.
Guess i will have to accept it for now and as i learn more about macros and
meta-programming, things will hopefully become clearer.

1 Like

What specifically about ExUnit tags are problematic?

1 Like

Just find that it works magically somehow

1 Like

@laiboonh as @Qqwy said, please let us know where you are struggling and think things are too magical and we can try to shed some light. This kind of feedback is helpful as well to know where we have gaps to fill for newcomers.

7 Likes

Thanks, will do. Will persevere with my learning and provide constructive feedback when possible.

1 Like