I think there's a stronger argument to be made for literal true / false,
not just truthy / falsy in Elixir than Ruby.

In Ruby, the return value might be used in an if-condition. Semantically,
it shouldn't matter if the value is literal true or simply truthy.
Something like `if method? == true` would be considered bad code.

In Elixir, you might also use the value in pattern matching. Matching on
literal `true` would be considered completely reasonable. Example:

    def entrypoint(data), do: handle(data, valid?(data))

    def handle(data, true), do: something(data)
    def handle(data, false), do: something_else(data)

Returning truthy / falsy values would hobble this sort of pattern matching.
It would be even worse if I only did a literal match on false, and ignored
the in the true case, which would then be run for the falsy value nil.

Another consideration is that a truthy value could potentially be large,
and could then be sent off in a message to another process in the
expectation that it's small.

So please, return literal true / false from your predicate functions.

- Martin

ons 24 aug. 2016 kl 15:28 skrev Michał Muskała <mic...@muskala.eu>:

>
> > On 24 Aug 2016, at 15:24, Elliot Crosby-McCullough <elliot...@gmail.com>
> wrote:
> >
> > Follow-up question; there's debate in Ruby as to whether methods ending
> in `?` are supposed to return actual booleans or just "truthy" and "falsy"
> values.
> >
> > Is there a similar debate in Elixir or has it been more strictly defined?
>
> I've heard José state, that if it were possible, it would be an error for
> a ? function to return a non-boolean. I am equally of conviction that only
> strictly boolean values make sense in this context.
>
> Michał.
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elixir-lang-talk+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-talk/DE691B14-076D-4FE1-B9B6-9E76FC7890A0%40muskala.eu
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-talk/CAAHw6C%2B2mL7zHOyVsFJ1UzSg9wVFrjcbc7sWGeEY%2B%3D9987nDpw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to