Eq or == which is the preferred idiom?

for comparing objects properties, which notation is considered most
idiomatic and best practice?

Thanks,

Jed S.

On Wed, Jul 20, 2011 at 10:29 AM, Jed S.
[email protected]wrote:

http://rubyforge.org/mailman/listinfo/rspec-users

eq uses == under the hood. eq is the idiomatic approach for two
reasons I can think of:

1.) It is more readable
2.) It is part of the “equality” DSL: eq, eql, equal.

More info here:
http://relishapp.com/rspec/rspec-expectations/v/2-6/dir/built-in-matchers/equality-matchers

On Jul 20, 2011, at 11:29 AM, Jed S. wrote:

for comparing objects properties, which notation is considered most idiomatic
and best practice?

Traditionally it was ==, but Ruby emits a warning. I’ve personally been
moving toward eq, and if I had it to do over again that’s all that would
be there. I have no intention, however, of deprecating == as there is a
wealth of code out there that uses it and users who prefer it in spite
of the warning from Ruby.

HTH,
David

On 20 Jul 2011, at 18:18, Justin Ko wrote:

rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users

eq uses == under the hood. eq is the idiomatic approach for two reasons I
can think of:

1.) It is more readable
2.) It is part of the “equality” DSL: eq, eql, equal.

More info here:
http://relishapp.com/rspec/rspec-expectations/v/2-6/dir/built-in-matchers/equality-matchers

I recently discovered eq, and one thing I like is that you can pass a
custom failure message, as you could with a traditional assert:

"foo".should eq("bar"), "what is wrong with your foo?"

I expect this is also possible with == but it would look ugly.

cheers,
Matt


Freelance programmer & coach
Author, http://pragprog.com/books/hwcuc/the-cucumber-book (with Aslak
Hellesy)
Founder, http://relishapp.com
+44(0)7974430184 | http://twitter.com/mattwynne