4 ms·
This might be a fun challenge for experienced rubyists, but I do not think this is a good way to learn Ruby. I only looked at Ruby Basics, but here's my feedba
by jeffrwells 13y ago
This might be a fun challenge for experienced rubyists, but I do not think this is a good way to learn Ruby.
I only looked at Ruby Basics, but here's my feedback:
The challenge is to solve: 'true and 0 && !nil and 3 > 2', but this is not a real-life application.
The words 'and' and 'or' should not be used for boolean comparisons, they are intended to be used to join two separate clauses such as "render 'template' and return" in rails.
Comparing a number and bang-nil is not good code. This could actually come to be if you were doing something like: "object.value && !object.value". However, you wouldn't ever want to hardcode "0 && !nil". If you were really checking for nil, you should use "!object.nil?"
I'm afraid that these challenges will teach bad code techniques to newbies who don't know the difference. But again, as someone with more familiarity with Ruby, I think these types of challenges are fun, but if that is the goal there is no need for the tutorial beforehand.
- arikrak 13y agoThanks. The challenge was meant as a way to review the different booleans, instead of 'real code'. I added a warning, but I'll see if other code would be better.
- Argorak 13y agoThe biggest problem is that the interesting part about this challenge (different precendence) is rather advanced to beginners and is _not even touched_ in the preceding parts.
- SnacksOnAPlane 13y ago> The words 'and' and 'or' should not be used for boolean comparisons, they are intended to be used to join two separate clauses such as "render 'template' and return" in rails. Is that true? Because I found a bug in our code recently that was in a line like render_error and return where the return was never getting called because render_error returned false. I don't understand why you would write code like that when you could simply write: render_error return and not have to deal with thinking about whether render_error could ever return a falsey value.