Exercism: Bob

I believe that the top-level function (the cond) should be a restatement of the problem specification. It should be written using terms in the problem domain (teenagers) not the solution domain (whitespace, upper case, etc.). E.g.:

  def hey(input) do
    cond do
      question?(input) -> "Sure."
      yell?(input)     -> "Whoa, chill out!"
      nothing?(input)  -> "Fine. Be that way!"

      true -> "Whatever."
    end
  end

See how that code pretty much reads like the assignment for the problem. This is a big advantage of functional programming.

The implementation of these should then be done at gradually lower levels of abstraction. Here’s my solution: http://exercism.io/submissions/e7f0b1696ed14eaa99bc72bf882f2459

4 Likes