|
|
|
|
|
by tchow
3398 days ago
|
|
While action fallback sounds pretty useful, it feels like a framework solution to a language problem. The language just doesn't handle nested if statements very well. Also writing elixir always feels like the lines of code are longer than the width of my IDE. It is so much text... My Elixir (and phoenix) experience so far, has been far from amazing contrary to all the hype on hn all the time. |
|
Elixir is a functional language, and while it's not pure, nested if statements deliberately do not belong.
The if statement itself is actually just a macro to a case/switch, the only reason it is there is to reduce the verbosity in cases where only one conditional branch is needed, José felt the practicality of this outweighed the fact it may get abused.
To use Elixir properly is to try and move away from conditional constructs as much as is realistically possible. This means instead using pattern matching, guard classes and multiple clause functions (both named and anonymous).
Once you take advantage of these you'll find your code stays flatter while keeping the individual branches of your conditional logic tied up into small independently testable functions.
If anyone would like to read more, I found these [1] [2] to be helpful.
[1] http://culttt.com/2016/05/30/branching-conditionals-elixir/
[2] http://blog.lucidsimple.com/2016/01/24/pattern-matching-help...