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.

Edit:

@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 introduction.md 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 about.md however.

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

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

@kotp Thank you for the pointer.

Will do.