Hi. I thought this unless / else example was confusing.
The text doesn’t match the condition and the else case is missing.
unless value < 2
"1 is not greater than 2"
end
# => "1 is greater than 2"
Maybe this PR can clear that up.
Hi. I thought this unless / else example was confusing.
The text doesn’t match the condition and the else case is missing.
unless value < 2
"1 is not greater than 2"
end
# => "1 is greater than 2"
Maybe this PR can clear that up.
Welcome to the Ruby category of the forums and thank you for considering a pull request. Even if this is not accepted, it is still a contribution that is greatly appreciated.
The current version of the examples in the Introduction and About are accurate:
If you run the examples they will answer truthfully, and give feedback that is also true.
I would also advise against the else
statement for unless
as if this were to exist it is easily argued that it should become an if
statement instead by reversing the conditional branches. This is a large reason that I have pressed against even showing an example of its use, though it is valid syntax.
When reading this, though, I agree it can be confusing, as there is an effect that comes in play here, and the unless
can add a multiplier to that difficulty rating.
I am also not seeing the text (or have not identified the text that you are referencing that does not match). Unless this is taken out of context that value = 1
, then it makes no sense.
The statement is “answer that 1 is not greater than 2 unless 1 is less than 2”.
If that does not happen, then 1 is greater than 2, which we know can not be the case mathematically speaking.
I think it is the case that we only need to change “greater” to “less” on the line that reads:
# => "1 is greater than 2"
@Meatball would be able to give some backstory to this as well, I believe.
Further discussion is welcome, but at this point in time, I am not inclined to open the PR up, until the work is decided.
I think the root cause is that it is just a typo, but we can remove that example, I think this has been discussed before.
Thank you for the thorough explanation.
In the Unless statement paragraph on the same page there is this other example:
unless value > 2
"1 is not greater than 2"
end
# => "1 is not greater than 2"
The statement for this, as I understand it, would be “answer that 1 is not greater than 2 unless 1 is greater than 2”, which I think is clear.
And then it is confusing to see the example we were discussing have the same answer but with the opposite condition.
I agree with the reasoning for not even having an unless / else example.
I’m not a maintainer of the ruby track, but here’s my 2 cents:
Fully agree, but then what is the point of even having an example of an unless
under an ## Else statement
heading?
I disagree, when seeing a comment with a =>
an the start I expect it to have the value of previous expression evaluated, like an irb session.
unless value < 2
"1 is not less than 2"
end
# => "1 is less than 2"
In this example, where is "1 is less than 2"
coming from? I would have expected # => nil
.
In my opinion there are two viable options:
else
clauses to unless
like in the linked PRunless
example from the else
subheading (avoid teaching students the unless-else entirely)We’ve definitely had this whole conversation before. I started that I feel like unless/else
examples should be removed. I have no memory of why that didn’t happen (maybe it was on me and I never did it?) but I think it’s the right solution.
Removing the whole
unless
example from theelse
subheading (avoid teaching students the unless-else entirely)
So I’m very on this
I agree about the misleading =>
as well, as it seems to be a word explanation of where you are, rather than what the expression is, confusing the conversation. Even reading it I had to struggle with what was conversational and what was code expression, and what was comment. If it were an IRB session, it would have been making some things clear.
The words used were conversational, as well. If this were in a method and ``value` were given, then the effects would be better understood to someone that already knows, but this is a concept document meant to be used for someone that does not understand yet.
For someone that does not know about the difficulties of unless
and else
we can leave out the else
references for unless
and let them discover it as they gain experience.
Fully agree, but then what is the point of even having an example of an
unless
under an## Else statement
heading?
I would prefer if there was not even a mention of unless with else
at all. And would not want examples of it in encouragement of its use. I believe it is there because “and unless
” is in the paragraphs next to if
concerning else
.
@clauddzy I believe the work to be done is:
unless
with the else
discussion.# =>
means “evaluated as”.I will re-open the PR if that work is agreed to.
# => "1 is less than 2"
This to me appeared to be a poorly formatted comment that expressed the condition of the implicit else
. And since it is always true that 1 is less than 2, it confirms the state, but does not provide an evaluation. In other words, the evaluation would have been nil
. This is why I consider it a typo in the meaning of the expression as the experienced would read it. As comment, though, it is malformed, and the typo includes the =>
portion of the comment.
Congratulations on your first accepted and merged contribution to open source in general!
You can mark this conversation with a Solved flag.