Ad
  • Custom User Avatar

    One thing to mentioned, in Elixir Programming:

    The reason I’ve waited so long to introduce them is that I want you to try not to use them much. You definitely will, and should, drop the occasional if or case into your code. But before you do, consider more functional alternatives. The benefit will become obvious as you write more code—functions written without explicit control flow tend to be shorter and more focused. They’re easier to read, test, and reuse. If you end up with a 10- or 20-line function in an Elixir program, it is pretty much guaranteed that it will contain one of the constructs in this chapter and that you can simplify it.

  • Custom User Avatar

    Thanks. I am new to it and don't know which one is best practice.

  • Custom User Avatar

    In this case I would not say one is better than the other. In a lot of more real world cases I do prefer different function heads to catch or guard against non-happy path implementations. Mostly because this prevents deep nesting of conditions which can quickly become hard to read.

  • Custom User Avatar

    Is this better than cond?
    Could someone please tell me? Thanks.