I have only recently started looking over the Ruby language, being
interested in it for a while, but not having enough information to
play with it very well until I picked up the pickaxe book (thanks,
guys!). As I’ve been looking around, though, I came to Hugh Sasse’s
page on relational operators in Ruby[1], originally mentioned in
[ruby-talk:6561]. In this page, he mentions specifically that Dave
Thomas brought up the following objection:
Dave Thomas in [ruby-talk:6562]:
Would ‘==’ produce it’s RHS on success? If so,
x == nil
would always be false.
I’m planning to keep my eyes open as I code to see how often this
would be useful for me.Nice proposal.
In [ruby-talk:6572], Hugh says he’d probably exclude == and !=.
I don’t honestly know the state of this proposal (there’s no mention
of it in the Pickaxe book, which may or may not mean anything), but
I think it would be a very good thing, and disagree that == and !=
should be excluded.
I’ve spent many hours in the last several years working in Oracle
and other SQL databases, where the special value NULL has to be
handled with care, because the only thing which is true about NULL
is that it doesn’t equal anything, even NULL. (This might be said
that NULL != NULL, but a quick test against another SQL database
says that this relational test returns false as well.) The only
valid test available for NULL is “IS [NOT] NULL”.
I think that this is a Good Thing, personally, and wouldn’t mind
seeing it so in Ruby. I think it would actually match the PoLS, even
though it is a change in existing behaviour. The way I see it, nil
is a special value. Even though nil is represented with a singleton
object, nil for an Object is not necessarily the same as nil for an
Array in a logical sense.
I know I’m bringing up stuff that might be close to two years old,
but I haven’t seen any further discussion on this, and I thought
that it might be worth mentioning about how other systems implement
the handling of NULL/nil values.
-austin
[1] http://www.eng.cse.dmu.ac.uk/~hgs/ruby/comparisons.html
– Austin Ziegler, austin@halostatue.ca on 2002.06.13 at 09.54.27