On Wed, Feb 7, 2018 at 12:51 PM, Herbert Voj����k <herby@mailbox.sk> wrote:


Esteban A. Maringolo wrote:
I wouldn't start a flamewar on this, but being able to separate
equality and identity is important.

Otherwise we should have to remove #= or #== since of either is redundant. :)

If you're dealing with ORM having a good implementation of #= is
important, since you might have several instances representing the
same "abstraction" (I wouldn't call it an object). Then you have to
implement #hash as well.

What is wrong most of the times is the implementation of #= and #hash itself.
I remember that Eclipse for Java provides Herbert's required feature,
where it can coherent equals() and hashcode() functions based on the
attributes of your choice.

Regards!

Esteban A. Maringolo


2018-02-07 17:09 GMT-03:00 Norbert Hartl<norbert@hartl.name>:
I think that implementing = and hash is almost always wrong. So I guess the answer is no :)

Just as mechanically generated initializers / accessors are not always directly what you want, you then change them later, but: it is helpful to be able to generate the default version of them.

I though the same for the #=/#hash pair.

Never thought it would cause a flame (just a "is it important enough" discussion)...

I agree it is important to have tools that help with commonly done operations. So, I'm generally in favour of making such a tool available.

By default, generate comparisons of all the class's instance variables, inheriting non-Object implementations via super, when there are any.

If there exists metadata for the instance variables, perhaps that metadata could be augment to indicate which instance variables are relevant to the object's uniqueness. And in such a case, the generator could restrict itself to such instance variables, by default.

��

Herby

Norbert

Am 07.02.2018 um 17:10 schrieb Herbert Voj����k<herby@mailbox.sk>:

Hi!

Do you think it would be reasonable to have, a la "generate accessors" / "generate initialize method", a "generate equality" thingie that would generate #= and #hash for the method, mechanically?

Just created a new "piece of data" class and felt like it would be helpful.

Herby