Directionality of comparasion operators

Hi,
maths says that the value of expressions like x == y and y == x is
always equal. And indeed most programmers wouldn’t think twice about
using x < y instead of y > x (except maybe those versed in machine
language…).

But direction does matter in ruby, where operators are just messages
sent to the left operand. This often bites me when using ===.

Have you had bugs fixable by rotating an expression?

On Tue, May 27, 2008 at 7:34 AM, Tobias W. [email protected] wrote:

Hi,
maths says that the value of expressions like x == y and y == x is
always equal. And indeed most programmers wouldn’t think twice about
using x < y instead of y > x (except maybe those versed in machine
language…).

But direction does matter in ruby, where operators are just messages
sent to the left operand. This often bites me when using ===.

=== is not, and is not intended to be the same as ==, nor is it
intended to be symmetrical.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On May 27, 2008, at 4:34 AM, Tobias W. wrote:

But direction does matter in ruby, where operators are just messages
sent to the left operand. This often bites me when using ===.

Have you had bugs fixable by rotating an expression?

There are other operators that aren’t commutative (like /), but it
does take extra thought to remember that === is among them. That bit
me in a recent post here.

///ark

On Tue, May 27, 2008 at 6:34 AM, Tobias W. [email protected] wrote:

Hi,
maths says that the value of expressions like x == y and y == x is
always equal. And indeed most programmers wouldn’t think twice about
using x < y instead of y > x (except maybe those versed in machine
language…).
But direction does matter in ruby, where operators are just messages
sent to the left operand. This often bites me when using ===.

Have you had bugs fixable by rotating an expression?

Operators depend on context (think of the use of <). === is no
different. There are, after all, a limit to the symbols you want to
remember, right :slight_smile:

A number of symbols cannot be overridden during the interpretation of
a script/program, such as &&, ternary operator, assignment operators,
and several others.

When, I first saw ===, I immediately hit the docs out of curiosity,
having never seen it before, and therefore never had a problem with
it.

Todd

On May 27, 2008, at 7:36 AM, Todd B. wrote:

When, I first saw ===, I immediately hit the docs out of curiosity,
having never seen it before, and therefore never had a problem with
it.

I like the moniker David Black cites: “the threequal operator.”

///ark

On Tue, May 27, 2008 at 10:48 AM, Mark W. [email protected] wrote:

On May 27, 2008, at 7:36 AM, Todd B. wrote:

When, I first saw ===, I immediately hit the docs out of curiosity,
having never seen it before, and therefore never had a problem with
it.

I like the moniker David Black cites: “the threequal operator.”

It’s cute, but I think it gives the wrong impression that === is
another form of ==, it’s really not, since it’s prime motivation is
use with the case statement, I think it’s better to think of it has
having a meaning more like a general sense of ‘matches’.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On May 27, 2008, at 7:57 AM, Rick DeNatale wrote:

[‘threequal’ is] cute, but I think it gives the wrong impression
that === is
another form of ==, it’s really not, since it’s prime motivation is
use with the case statement, I think it’s better to think of it has
having a meaning more like a general sense of ‘matches’.

Since case statements are traditionally about comparing values (in
Cxx), I can buy that === is an extension of that. In any case, what’s
a better name? “The case matching operator” doesn’t exactly trip off
the tongue. :slight_smile:

But your point is taken.

///ark

In article [email protected],
Mark W. [email protected] wrote:

Cxx), I can buy that === is an extension of that. In any case, what’s
a better name? “The case matching operator” doesn’t exactly trip off

= assignement
== equality
=== likeness?

On Tue, May 27, 2008 at 11:14 AM, Tobias W. [email protected] wrote:

In article [email protected],
Mark W. [email protected] wrote:

Cxx), I can buy that === is an extension of that. In any case, what’s
a better name? “The case matching operator” doesn’t exactly trip off

= assignement
== equality
=== likeness?

No, I don’t think that

3 is like the range (0…5)
or
1.2 is like the class object Float

or
“abc” is like the regexp /…/ or /[abc]{3}/ or …

perhaps === means something more like “recognizes as one of its own.”


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

In article [email protected],
Mark W. [email protected] wrote:

=== likeness?

Except that likeness is commutative. If one thing is like another,

Right. The match operator =~ clearly looks directional.
membership?

On May 27, 2008, at 8:14 AM, Tobias W. wrote:

= assignement
== equality
=== likeness?

Except that likeness is commutative. If one thing is like another,
then vice versa.

///ark