[erlang-questions] case statements really required??

Kiran Khaladkar <>
Mon Dec 7 10:18:35 CET 2009


Richard O'Keefe wrote:
>> kiran wrote:
>>> hi,
>>> is it good to use case statements in functional language..  
>>> according to me .. pattern matching-functions could do the task.
>>> any commnets??
>
> Multiclause pattern-matching functions and case expressions do exactly
> the same thing; except for the error message you get when there is no
> match either can be trivially converted to the other.
>
> You should consider questions like
>
> - can you give this part of your program a meaningful name?
>   [If so, it might make a good function.]
>
> - would this part of your program be useful elsewhere,
>   perhaps with a few constants replaced by variables?
>   [If so, it might make a good function.]
>
> - is the normal flow of your code obscured by bulky code that
>   could be moved elsewhere?
>   [If so, it might be useful to split it out as a function, or
>    you could use a literate programming tool, but in either case
>    you'll have to find a good name for it].
>
>
thanks that was really helpful comment.
I got that both case statements and pattern matching are both the same 
after looking at the object code :) of both. Erlang converts both case 
statements and function head matching to the same thing.


More information about the erlang-questions mailing list