exercism / elixir-analyzer

GNU Affero General Public License v3.0
30 stars 32 forks source link

`two-fer` doesn't recognize default argument unless it is `"you"` #431

Closed skeltoac closed 1 month ago

skeltoac commented 1 month ago

Analyzer emits the following message for the code below.

Recommended
Use a default argument for this solution.
defmodule TwoFer do
  @doc """
  Two-fer or 2-fer is short for two for one. One for you and one for me.
  """
  @spec two_fer(String.t()) :: String.t()
  def two_fer(name \\ "") # This is a function head with a default argument.
  def two_fer(""), do: "One for you, one for me."
  def two_fer(name) when is_binary(name), do: "One for #{name}, one for me."
end
NobbZ commented 1 month ago

I do not really consider the example neither idiomatic, nor valid.

How do I produce "One for , one for me."?

If at all, nil might be used as a semi idiomatic approach.

jiegillet commented 1 month ago

@NobbZ I agree with you about the example code here.

What needed fixing was the disconnect between the analyzer comment telling you to use a default argument when in fact you were using one. The changes that closed this issue addressed that point, further discussions on idiomaticity (is that a word?) or validity belong to a mentorship session.