Hacker News new | past | comments | ask | show | jobs | submit login

Not much of an Elixir developer but if I saw that snippet in code review I would flag it for readability.

Just 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.




Disagree, you probably think it's unreadable because you don't know the language and/or concepts in this snippet.

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.


I've been writing Elixir for 5 years and I agree with the OP: I dislike the Ampersand syntax immensely. I find it a major impediment to readability.


I never quite understand this mentality that many engineers have.

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?


Because it’s not about growth it’s about the ability for a large team (and changing over time) to reason about a single code base.

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 don't know this language, so I would reject the snippet in code review″

I certainly hope that for the sake of integrity, you would decline reviewing a language that you don't know.


This example is not so difficult to understand.

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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: