|
|
|
|
|
by tinco
4852 days ago
|
|
This article isn't about replacing symbols with words, ruby isn't about replacing symbols with words either, and there is no place in the article where the author states that a = true and false
is prettier than a = true && false
And if you would actually have read the article and paid close attention you would have learned that the two lines you just said are not functionally equivalent.No ruby programmer would ever have a line that says a = true and false
It just makes no sense.Maybe a very experienced ninja ruby programmer would, but that programmer would know exactly what he was doing. The beauty in ruby and in the 'and' keyword is that a ruby programmer intuitively knows when to use which. This article just clears up why exactly they work like you expect them to work. edit: maybe a weird programmer would do something like this @message = "We failed :(" and false
at the end of a function that has conditionals with return statements in them. |
|
> I quickly got into the habit of writing all of my boolean statements with these, instead of the more conventional && and ||, because my code became so much readable.
And I definitely agree with danso and disagree with the blog on this issue: the operators gives more structure to the code and makes it much easier to parse at a glance. With the 'and' version, I have to actually read the code to figure out what its doing; with the '&&' version, I can get the basic idea just from the code's "shape" (for lack of a better word).
I think being able to quickly grasp the idea at a glance is far more important than having code look like English.