pminten (16) [Avatar] Offline
#1
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 <http://www.haskell.org/haskellwiki/Declaration_vs._expression_style>.

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 (86) [Avatar] Offline
#2
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!