-
-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Refactor Concept]: conditionals #1597
Conversation
concepts/conditionals/about.md
Outdated
|
||
An `if` statement can be used to conditionally execute code: | ||
Ruby has what is known as control expressions, these are used to control the way the program will run and they take a truthy or falsey value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ruby has what is known as control expressions, these are used to control the way the program will run and they take a truthy or falsey value. | |
Ruby has what is known as flow control expressions, these are used to control the way the program will run and they take a truthy or falsey value. |
|
||
An `if` statement can be used to conditionally execute code: | ||
Ruby has what is known as control expressions, these are used to control the way the program will run and they take a truthy or falsey value. | ||
There are operators that can be used to create truthy or falsey values, these are known as [comparison operators][comparison-operators]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These operators are really methods. They are known as methods, even though this resource calls them "operators". Can we reference the Pickaxe book for this instead? We call the "Methods", correctly, in the table that follows below, as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I think operators are used in quite a few places and is often how they are referenced, sure they are methods (there are some expectations but this stays true for most cases) but in that case so does Ruby not have any operators since everything is just methods.
According to the C API docs for ruby: https://docs.ruby-lang.org/en/master/syntax/operators_rdoc.html
Are an operator defined such as (and says that there is such a thing as a operator):
"In Ruby, operators such as +, are defined as methods on the class. Literals define their methods within the lower level, C language. String class, for example.
Ruby objects can define or overload their own implementation for most operators."
There are multiple resources calling them methods. And the Ruby API even calls them conventional comparison operators: "Comparable uses <=> to implement the conventional comparison operators (<, <=, ==, >=, and >) and the method between?."
Link: https://ruby-doc.org/3.2.2/Comparable.html
And according to the number concept are they already called comparisons operator and that doc did either Jeremy or Erik write: https://github.com/exercism/ruby/blob/main/concepts/numbers/about.md.
As for referencing the Pickaxe book so can we only reference publicly available material and that is a paid resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think we really disagree here. I just want to ensure that it is clear that these "operators" are not really anything special, they are methods.
In general I think operators are used in quite a few places and is often how they are referenced, sure they are methods (there are some expectations but this stays true for most cases) but in that case so does Ruby not have any operators since everything is just methods. According to the C API docs for ruby: https://docs.ruby-lang.org/en/master/syntax/operators_rdoc.html Are an operator defined such as (and says that there is such a thing as a operator): "In Ruby, operators such as +, are defined as methods on the class. Literals define their methods within the lower level, C language. String class, for example.
And yet, even that document states and reinfoces "since operators are method implementations".
Ruby objects can define or overload their own implementation for most operators."
There are multiple resources calling them methods. And the Ruby API even calls them conventional comparison operators:
https://github.com/ruby/ruby/blob/8d0eb872e8fd0cc1837318c4c242f4085df9812e/doc/syntax/operators.rdoc#L4 is probably what I would choose to reference before I would defer to the unofficial (though still very good) rubyapi.org. Cory does a good job maintaining that site.
But coming from the official source, rather than even a recommended source from the official site. (Even when the official language page recommended some of my published content by Matz, I would still defer to the official sources.)
"Comparable uses <=> to implement the conventional comparison operators (<, <=, ==, >=, and >) and the method between?." Link: https://ruby-doc.org/3.2.2/Comparable.html
Yes, the word "operator" is used conveniently in the documentation, concerning <=>
method. I do not begrudge that.
And according to the number concept are they already called comparisons operator and that doc did either Jeremy or Erik write: https://github.com/exercism/ruby/blob/main/concepts/numbers/about.md.
Yes, I never said that there are no operators, just that we might want to mention that these "operators" are methods. Since we reinforce that in the table later, as well. (Which may reduce some confusion, since we say operator and then almost immediately list them as methods in the table.)
As for referencing the Pickaxe book so can we only reference publicly available material and that is a paid resource.
The PIckaxe book is available online for free, while yes, it is also a paid resource, http://ruby-doc.com/docs/ProgrammingRuby/
Much of it is fairly evergreen, and these "operators" have been methods since even earlier than that book was written, and we can note where things have changed in newer versions of Ruby. This is not one of those areas, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean Ruby api is just rubys "offical" api, but just Class and Module Index and in my view a lot nicer user interface. And it is part of documentation on the official site so I say why not.
The other text "https://github.com/ruby/ruby/blob/8d0eb872e8fd0cc1837318c4c242f4085df9812e/doc/syntax/operators.rdoc#L4" comes from the ruby C API which is a doc intended for work on the core of Ruby or extensions of Ruby, not really intended for casual ruby developers but it does have a pretty decent explainer of what an operator is. So I am not against to include a link to the C API for explainer what an operator is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source code is what is used to create/generate the documentation. It changes when you look at a version of the documentation, and can match it to the same for the repository.
What this means, if we link to the current tree link, rather than a specific blob, is that the link will be up to the minute up to date. I did show the current at the time though, it may have already been updated.
It is also why I usually suggest generating the documentation locally, as then you can be sure to be reading the documentation for the version you are using, rather than potential mis-matches when you go to a web resource for generated documentation there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What this means, if we link to the current tree link, rather than a specific blob, is that the link will be up to the minute up to date. I did show the current at the time though, it may have already been updated.
It will link to the latest official release of Ruby so it doesn't include unstable/preview changes. But yes this could lead to mismatched version, idealy there would be some kind of system around this. But feels like it is better to have it lose, since at least I find it better to have the docs linked to the version used by tooling/test runner (which runs the latest version). But idealy we would have a script that could update the docs when we update the test runner.
| > | greater than | 3 > 1 | | ||
| >= | greater than or equal | 2 >= 2 | | ||
|
||
The equal and not equal operators can be used to compare any type of value contrary to the operators already mentioned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The equal and not equal operators can be used to compare any type of value contrary to the operators already mentioned. | |
The equal and not equal methods can be used to compare any type of value contrary to the operators already mentioned. |
concepts/conditionals/about.md
Outdated
# Execute logic in all other cases | ||
## If statement | ||
|
||
The [`if`][if] statement is used to check if a given condition is truthy or falsey. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The [`if`][if] statement is used to check if a given condition is truthy or falsey. | |
The [`if`][if] statement is used to check if a given condition is "truthy" or "falsey". |
Quotes since this is not a "normal" expression, things being either truth or false, while we are introducing an idea of not strict Boolean evaluation.
Not a blocker, though, for sure.
concepts/conditionals/about.md
Outdated
unless value < 2 | ||
"1 is not greater than 2" | ||
else | ||
"1 is greater than 2" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is perhaps considered a poor example, as we should prefer to not use else
with unless
. The indication is that the conditional statement is probably "backward" or "opposite of what is wanted".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, with or without reference changes. The references are good, the detail of the operators being methods that can be modified will come out at some point, and do not necessarily need to come out here or in direct references. (In other words, not a hill to defend to the death, for sure.) ;) Good work on the refactoring so far, for sure!
The aim is to clean up the docs from mentions of integers, and also to expand on the concept.