[erlang-questions] case statements really required??

Richard O'Keefe ok@REDACTED
Mon Dec 7 02:29:26 CET 2009


> 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].




More information about the erlang-questions mailing list