by quickthrower2 · 4y ago · 0 comments
I am kind of impatient, so it seems a bit annoying to me.
If I were learning something technical that I am new to, say flying a plane, or biology I would prefer just to get stuck in. I would expect a pedagogical approach of course to easy me into it. But the cutesy stuff would feel like unnecessary slowing me down.
The main selling point of Elixir is concurrency. Dave Thomas gives this great example in the second page of his book [3]:
defmodule Parallel do
def pmap(collection, func) do
collection
|> Enum.map(&(Task.async(fn -> func.(&1) end)))
|> Enum.map(&Task.await/1)
end
end
result = Parallel.pmap(1..1000, &(&1 \* &1))
Elixir developers can see the beauty of that snippet. However, for beginners, it can be overwhelming or intimidating. If you want to understand what is going on, you first need to learn about enumerables, map/filter/reduce, lambda functions, capture and pipe operators, spawned processes, tasks, etc. Yes, that is a great example for showing the power of Elixir but if you are a beginner chances are you are looking for something easier (e.g., Joy of Elixir).Take Nix and NixOS [4] for example. That is an impressive technology and it has a (not cutesy) documentation. But, as a beginner, I feel lost. I rather prefer a cutesy getting-starter tutorial or book.
So, yes, I think there is a niche for developers that want to start with cutesy material. It is just a matter of taste.
[1] https://learnyousomeerlang.com
[2] http://www.learnyouahaskell.com
[3] https://pragprog.com/titles/elixir16/programming-elixir-1-6
do_work = Task.async(fn -> long_calculation() end)
That kicks off the new task, at some point later we should obtain and examine the result: result = Task.await(do_work)
https://hexdocs.pm/elixir/1.13/Task.html#await/2Just because you can write something in 3 lines of code using lots of nesting and anonymous functions and variables doesn’t mean you should. This code would do better if it was longer, the variables had names, and the transforming functions broken out and named.
But does that mean we shouldn't, for example, use destructuring in javascript because some devs might not know it.
At some point you have to assume a common ground of knowledge, and that common ground in Elixir is somewhat different than in algol derived OOP mainstream.
Instead of taking advantage of advanced language features and teach them to people, we more often than not create rules to avoid using them because "someone else won't understand it".
Why not grow people instead of lowering the bar?
Why not rewrite your entire business logic into a succinct DSL based on macros? Because making lower level or refactoring changes would be a headache.
I certainly hope that for the sake of integrity, you would decline reviewing a language that you don't know.
The important thing to realise is that the dot operator is used to access functions grouped into modules (or even invoke anonymous functions) rather than invoke methods on an object. Because Elixir being a functional language, the central operation is invoking functions on data and passing the results to other functions, rather than calling methods on objects.
From this understanding you can just grok from the code that this is a program that takes a list of numbers and squares them concurrently, in the process using your computer’s parallel processing hardware. And as this is a high level language you can create concurrent workloads with minimal implementation knowledge.
Even if you come from C family of languages where the & denotes something to do with address, you’ll realise the way Elixir uses it is not far away from that, but without the added tediousness of memory management. So elixir builds upon common conventions.
Some things like Enum may confuse a Java programmer. It’s Elixir speak for enumerable data rather than a collection of constants. And of course the pipe operator is different.
It’s certainly not easy to see this and write your own code and offer suggestions. But for a mildly experienced programmer who has already adopted the mindset that code is just a bunch of instructions presented in non-linear fashion, like in a legal document, this is an approachable intro to start asking questions from. First of all one should be willing to read a couple of pages from some book on what are anonymous functions and what is the syntax like for that etc.
The task is a bit more difficult for people who tend to look at code with a more inflexible viewpoint ie junior developers.
If you forget what it means in a month, you will probably have other problems than this single snippet.
I do agree with you though, when you get a screenful of ampersands that contains non-trivial business logic - it's not great.
I'd wish somebody to sell Elixir to me with transparent parallelism, demonstrating that it's literally 2-3 extra lines of code (compared to other languages where the extra code you have to write is significant). Pepper it with pattern matching and preemptive concurrency and I'm sold in 5 minutes.
I wish people stopped evangelizing.
Saša Jurić - The Soul of Erlang and Elixir: https://youtu.be/JvBT4XBdoUE
This is in my opinion the best demo of Elixir, the BEAM, OTP and any programming language, ever. If this doesn't pique your interest, nothing will.
On the other hand, if you're not quite there, or the technical qualities are not that impressive for your use case - the thing that may draw you into a language is how it encourages you to approach problems. How it lets you describe what you are expecting, and what to do when you are surprised. How to navigate data structures. For that latter category of person - I think the slow, cutesy approach makes a lot of sense. The goal is to fascinate and then seduce. No harm if you're not in the mood - but one day, a cutesy introduction may catch your eye. We all have different tastes.
For example for Elixir they have: https://exercism.org/tracks/elixir
What I did get from these Elixir guides (at least in my head) is that Ryan is always just being Ryan: a particularly great, proficient, and prolific writer of documentation. When he was writing about Rails, he was in his wheelhouse and he feckin' killed it and appealed to the exact right audience. When he wrote about Elixir, it was good but I felt he was out of his comfort zone and trying a new tone (the one you describe). This is purely my speculation but ya... again, just responding since this comment both made me a bit annoyed that you'd even bring this up (of course you have every right to), and struck a pretty hard chord with me.......and I'm tired and a little tipsy.
Anyway, massive respect to Ryan. I feel like he is one of the, if not The, unsung hero of Rails' popularity. The Rails guides are really special.
I think it stated that `=` "makes computer remember stuff", this is vocabulary aimed at 5 year olds.
In contrast, the seniors liked the pragmatic training better.