[Proposal] Deprecate unless-else

53 views
Skip to first unread message

Mikael Muszynski

unread,
Jan 3, 2019, 12:26:50 PM1/3/19
to elixir-lang-core
I would like to propose the removal of the ability to use `Kernel.unless/2` with an `else`-clause.

This proposal is inspired by the seeming consensus between the most prominent style guides for Elixir, along with similar consensus in the most often cited style guides for Ruby (where this ability exists as well).

Some examples for Elixir:
Similar examples for Ruby:
I have not researched the topic to the degree that I can point to some scientific study regarding how comprehensible negated booleans are. However, if the style guides are an indicator of community preferences, then anywhere they are enforced, `unless-else` will likely be banned.

I have nothing but intuition to go by when it comes to how many Elixir users are actually using style guides like the ones above (with or without automatic checking), but the people and companies I've worked with generally use these guides.

Therefore, this proposal is mostly a question whether this one rule should be enforced everywhere, at the potential expense of those who don't care much about style guides. I guess that also opens discussion about whether other rules could receive similar treatment, but that's a discussion for a different thread.

Josh Adams

unread,
Jan 3, 2019, 1:02:08 PM1/3/19
to elixir-l...@googlegroups.com
I really appreciate this suggestion. It would be a breaking change to the API, so that's a negative and implies that it couldn't actually happen until Elixir 2.0 I would assume. However, I can confirm that every single time I've seen an `unless/else` it has resulted in confusing logic and removing the option entirely will just make codebases clearer imho.

Josh

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/6fd77557-3080-496b-af5f-fe51cf9de79b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Josh Adams

Chris Keathley

unread,
Jan 3, 2019, 1:26:33 PM1/3/19
to elixir-l...@googlegroups.com
Given that it's a breaking change this wouldn't happen till at least some future version of Elixir so its not really a real discussion. That said, generally speaking the amount of times you need to break an existing api are close to 0 and definitely shouldn't be driven by what the community believes is a good or bad pattern at the moment. If people want to lock down subsets of the language then there are tools to do that. I'm not really defending `unless` `else` or its usage. But for better or worse its a part of the language and breaking the language should effectively never be an option.


For more options, visit https://groups.google.com/d/optout.


--
Chris

Parker Selbert

unread,
Jan 3, 2019, 1:56:42 PM1/3/19
to elixir-l...@googlegroups.com
If anything this seems more suited to be a warning rather than something deprecated and slated for removal. It would be similar to how the compiler suggests pattern matching on an empty list instead of length(list). The difference being that there are performance differences for pattern matching a list and using unless/else is purely confusing to humans.

Regardless of how it would be done, I don’t think this change *should* be done.

Ryan Winchester

unread,
Jan 3, 2019, 2:25:28 PM1/3/19
to elixir-l...@googlegroups.com
Have the formatter change it to an if/else 😈, or just leave it for tools like Credo to yell at you for an unless/else.

eksperimental

unread,
Jan 3, 2019, 7:54:57 PM1/3/19
to elixir-l...@googlegroups.com
On Thu, 3 Jan 2019 11:25:13 -0800
Ryan Winchester <he...@ryanwinchester.ca> wrote:
> Have the formatter change it to an if/else 😈, or just leave it for tools
> like Credo to yell at you for an unless/else.

This is definitely something the formatter should do. Formatter shouldn't change the semantics at
all, and the AST should remain the same before and after the formatting.

From the formatter documentation:

• --check-equivalent - checks if the files after formatting have the same
AST as before formatting. If the ASTs are not equivalent, it is a bug in
the code formatter. This option is useful if you suspect you have ran into
a formatter bug and you would like confirmation.

eksperimental

unread,
Jan 3, 2019, 7:57:17 PM1/3/19
to elixir-l...@googlegroups.com
On Fri, 4 Jan 2019 07:54:44 +0700
eksperimental <eksper...@autistici.org> wrote:

> On Thu, 3 Jan 2019 11:25:13 -0800
> Ryan Winchester <he...@ryanwinchester.ca> wrote:
> > Have the formatter change it to an if/else 😈, or just leave it for tools
> > like Credo to yell at you for an unless/else.
>
> This is definitely something the formatter should do.
SHOULD NOT DO!

Louis Pilfold

unread,
Jan 4, 2019, 4:34:50 AM1/4/19
to elixir-l...@googlegroups.com
I might be wrong, but I think the formatter already updates the AST in some places to fix deprecation warnings.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

José Valim

unread,
Jan 4, 2019, 4:40:00 AM1/4/19
to elixir-l...@googlegroups.com
It does, but it requires a special option to do it, which we are considering removing because it is not as useful as we thought it would be. :(


José Valim
Skype: jv.ptec
Founder and Director of R&D


Ryan Winchester

unread,
Jan 4, 2019, 2:07:32 PM1/4/19
to elixir-l...@googlegroups.com
> SHOULD NOT DO! 
That’s why I had the smiley devil face for that part.

I agree with Chris, it _should_ be left alone, as much as I’d like to think people using unless/else deserve to have their code broken...
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

eksperimental

unread,
Jan 8, 2019, 12:40:36 PM1/8/19
to elixir-l...@googlegroups.com
Sorry, I totally missed the smiley face, therefore the joke :-P

On Fri, 4 Jan 2019 11:07:29 -0800
Reply all
Reply to author
Forward
0 new messages