Include example for unless statement

Pull request message: “Includes an else example in the code making it more clear.”

After submitting the pull request it was closed by the bot and after reading the blog I presume it has to be discussed here first.

This is my first pull request on Exercism so I’m not aware of the process around here.


@iHiD commented on Github that unless/else is considered an anti-parrern and using if/else is a better choice.

I think we should also mention this in the instruction with the example.

Pull request created at exercism/ruby#1688.

Are the instructions supposed to be mentoring? I think that is often where this information comes out, if the practitioner requests a review or mentoring. It may be an automated comment as well, from the analyzer, if the code has an unless with an else statement.

Further, this information, while not in the example is listed:

The `else` statement can be used in conjunction with the `if` and `unless` statements.
The `else` statement will be executed if the `if` branch or the `unless` branch is not executed.

And the example correctly does not unless with else.

We might be covered.

Is the reader supposed to assume using else in conjunction with unless is not a good practice because the example excludes it?

I do not know, and would not know until I received a mentor request, and they chose to use an explicit else statement, at which point I would talk to them about implicit else and we would go from there.

The person might ask “Why was there not an example showing an else with an unless?” and we could talk about that as well.

I would be up for mentioning that unless..else..end is probably something indicating that this is an if statement in disguise, that the branches are likely in the wrong order.

Agreed. This sounds like a good insight to add to the instructions.

Will add it to the pull request and post here.

1 Like

I will see it when you make the change in the closed patch as well.

The should only discuss things that are relevant to the exercise. unless/else isn’t so it’s not appropriate content for that file. It could be included in the however.

@ beamaddict to be clear, because there is no current file, do reference the other files to hopefully get some inspiration for that file.

  • concepts/advanced-enumeration/
  • concepts/arrays/
  • concepts/basics/
  • concepts/blocks/
  • concepts/booleans/
  • concepts/case/
  • concepts/conditionals/
  • concepts/enumeration/
  • concepts/exceptions/
  • concepts/floating-point-numbers/
  • concepts/instance-variables/
  • concepts/loops/
  • concepts/modules/
  • concepts/multiple-assignment-and-decomposition/
  • concepts/nil/
  • concepts/numbers/
  • concepts/ostruct/
  • concepts/ranges/
  • concepts/strings/
  • concepts/symbols/
  • concepts/ternary-operator/

@kotp Thank you for the pointer.

Will do.