-
Notifications
You must be signed in to change notification settings - Fork 248
Ruby: Authoring kata #252
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
Ruby: Authoring kata #252
Conversation
| To avoid the above problems, calls to assertion functions should respect the following rules: | ||
| - The expected value should be calculated _before_ invoking an assertion. The `expected` parameter passed to the assertion should not be a lambda/`Proc`/block, but a value calculated directly beforehand. | ||
| - Appropriate assertion functions should be used for each given test. `Test.assert_equals` is not suitable in all situations. Use `Test.expect` for tests on boolean values, and `Test.expect_error` to test error handling. | ||
| <!-- Use `Test.assert_approx_equals` for floating-point comparisons --> |
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 would explicitly mention that there's no assertion for approx equality, because it's somewhat unexpected IMO. Every sane assertions library has it. Snippet is a great idea, just mention it here and link to it.
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.
We can add the snippet to the test framework (https://github.com/codewars/ruby-test-framework) that will be used for Ruby 3.0 support. I'm also considering to use RSpec under the hood somehow, then eventually switch to it completely like JS.
content/languages/ruby/authoring.md
Outdated
| - Avoid returning different data types depending on the situation (_"Return the result, or the string 'Error' if no result can be found..."_). Ruby is dynamically typed, which is not the case for some other languages. Returning `nil` might be appropriate in some situations, but throwing an error might be better in others. | ||
|
|
||
| Some kata just should not be translated into Ruby because it can be difficult to keep their initial idea: | ||
| - Some kata might be meant for another language specifically. For example, a kata about `Python: Learning Classes` should probably not be translated to Ruby, even though Ruby has `class` syntax. |
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 don't feel like it's evident. I practice both (well, not much ruby, yeah, but still) and I honestly don't see why this should be avoided in ruby => ?
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.
You probably could, but you'd want to change the kata title at least, right?
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.
oh... But if it's only about the title, I feel the reason is out of place, then (but maybe it's just me being oriented by what I knew will follow...?)
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 think I just need a better example of something that shouldn't... any ideas?
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.
maybe something what does not translate well into hashes, or duck typing?
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.
You can technically do duck typing in Ruby...
Maybe like something about JS coercion? Ruby doesn't have coercion (yay).
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.
Damn I am so noob in Ruby I have no idea what could apply here.
Maybe dudner methods? Coercion sounds good too.
Maybe just leave this out?
I KNOW! Performance kata do not translate well into Ruby! :D
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.
Dunder methods sounds right.
| - Some kata might be meant for another language specifically. For example, a kata about `Python: Learning Classes` should probably not be translated to Ruby, even though Ruby has `class` syntax. | |
| - Some kata might be meant for another language specifically. For example, a kata about `Python: Dunder Methods` should probably not be translated to Ruby, as Ruby doesn't have dunder methods. |
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.
don't ruby classes have def coerce(self,other) mehtods? x)
even dunder methods are a bit edgy because some exist in ruby =, +, ...
maybe step out of python, for this? like "learn the difference int/long" in java/C/... doesn't translate to ruby.
?
Co-authored-by: hobovsky <hobson@wp.pl>
hobovsky
left a comment
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.
Looks good to me, but I am no Ruby expert so maybe someone else could also take a look.
kazk
left a comment
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.
Looks good to me. Thanks for writing this.
By the way, I'm considering to replace the custom test framework with the built-in minitest from Ruby 3.0. I'm still experimenting, but it should work the same way except for assertions, so this will be still relevant.
Discussion: #215
Deploy preview: https://deploy-preview-252--reverent-edison-2864ea.netlify.app/languages/ruby/authoring/