The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

pminten (16) [Avatar] Offline
In Chapter 3 you present head matching (function clauses) as a new and superior way of doing control flow, compared to the classical constructs of if and case. It's not that simple. This is a matter of programming style and different functional programmers have different preferences.

The chapter, at least the first parts, is essentially advocating declaration style. See <>.

You say that in Elixir constructs like if and case aren't used a lot because of head matching. On a quick search of the Elixir main repo I've found approximately 1500 case and if expressions and about 500 function clauses that use pattern matching (and of those some are false positives and many are clauses of the same functions). So it seems that the main Elixir codebase is written in a mix of >75% expression style and <25% declaration style.

Message was edited by:
pminten (clarify that 75% is lowerbound and 25% is upperbound)
sjuric (109) [Avatar] Offline
Re: Chapter 3: Declaration style vs expression style
That's a good remark, thanks!

I guess it's partially due to my Erlang heritage, where if is overly clumsy, so I almost never used it. Later, as I moved to Elixir, I often found myself relying even more on multi-clauses, because they also work nice with the pipeline operator and higher order functions.

That said, I agree with you the choice is not that simple and belongs to the personal style and preferences, so I'll try to revise it and be more objective about it.

Thanks again!