Significantly, "&&" > "=" > "and", which can lead to unintended results when refactoring "&&" --> "and"
Significantly, "&&" > "=" > "and", which can lead to unintended results when refactoring "&&" --> "and"
It seems like a landmine for someone learning the language and a place for bugs to creep in to code.
Pick one and go with it. The extra expressiveness or whatever a ruby person would call it, that comes from the alternate forms just doesn't seem worth it.
They did. It's `&&` and `||`.
I understand your point when it comes to it being a potential landmine, and honestly I never use them myself. But I've never seen any ruby guides or docs use `and` instead of `&&`, and I have seen skilled rubyists make great (and correct) use of `and`.
I assume you mean idiomatically chosen, since clearly the decision wasn't made at the language level.
> I have seen skilled rubyists make great (and correct) use of `and`.
I'm obviously not a ruby programmer, so it doesn't matter much to me, but it seems odd to argue that having a largely disused second set of logical operators in a language that skilled people periodically trot out for some cases is anything but a design wart. Maybe it's a cultural thing in the ruby world.
And, honestly, I don't mean that to sound snide or slighting. It's just odd to me.
> raise "ooops" unless do_something()
But even so, it reads a bit backwards. Some codebases do this instead:
> do_something() or raise "oops"
That's just repeating one of the examples in the article, but it jumps out to me as the one I've seen most often.
foo or do_something()
is exactly the same as if foo {
do_something()
}
Except the latter is WAY less likely to be accidentally misread.... and don't even get me started on do_something() unless fooA much better argument might be Use <feature> only when you fully grasp its use, which is true of any feature. Some are more difficult to understand than others, especially when trying to relate a feature to another language, but that's just not an argument I can support.
I'm not suggesting that everyone should understand every detail of every potentially misunderstood feature. I'm suggesting that these situations should be dealt with on a case-by-case basis.