[erlang-questions] Idiom for multiple case matches

mats cronqvist masse@REDACTED
Mon Nov 10 00:06:27 CET 2008

Michael Radford <mrad-direct-erlang@REDACTED> writes:

> I hesitate to wade into this cranky-fest, but IMO this is extremely
> clear and easy to read:
> 	is_vowel ($a) -> true;
> 	is_vowel ($e) -> true;
> 	is_vowel ($i) -> true;
> 	is_vowel ($o) -> true;
> 	is_vowel ($u) -> true;
> 	is_vowel (_) -> false.
> That's just saying directly what you mean in a language that's nice
> enough to make it reasonably efficient. 

  and what you mean is presumably that 'is_vowel' is a function that
  returns 'true' if its argument is a member of the list "aeiou",
  otherwise 'false'.

  the fact that this is a fairly common task is of course the reason
  why lists:member/2 exists in the first place. so by not using
  lists:member/2 here, you are obfuscating the fact that you are
  indeed testing if something is a member of a list. 

  this is why your function is bad. it has nothing to do with the
  number of lines, but the fact that your function hides its intent
  by not solving the task the obvious way.

  it is of course also true that, all else being equal, short is

  and the style of cut-and-paste programming you use is also bad. for
  example, it's easy to get lost in the paste-fest and forget that "y"
  is a vowel.

> I have had far more problems dealing with code written by "shortest
> possible source code maniacs" than I have with "premature
> optimizers."

  in that case a congratulate you. perhaps if you had spent a good ten
  years fighting losing battles against "premature optimizers" you'd
  be cranky too.


More information about the erlang-questions mailing list