Re: [Pharo-users] Equals and HashCode Builder

2017-10-07 Thread Sean P. DeNigris
Noury Bouraqadi-2 wrote > The code + tests are here > http://smalltalkhub.com/#!/~CAR/ReusableBricks/packages/Equals I forked to https://github.com/seandenigris/Pharo-Equals with a baseline to make it easier to try out/possibly-integrate. - Cheers, Sean -- Sent from: http://forum.world.st/

Re: [Pharo-users] Equals and HashCode Builder

2017-10-07 Thread Noury Gmail
Hi, I have developed few years ago a trait-based solution to make it easy to deal with equality. By default, instances of the same class with equal IVs are equal + have the same hash code. You can customize the list of IVs to compare, which is handy in case of IVs that store cache values. All y

Re: [Pharo-users] Equals and HashCode Builder

2017-10-06 Thread Stephane Ducasse
Contact noury because I do not remember. But having a little builder is also nice. On Fri, Oct 6, 2017 at 4:15 PM, Vitor Medina Cruz wrote: > Stephane > > "Vitor why don't you take it as a small project to propose a solution for > Pharo." > > I will try :) I like the idea of using a Trait. > > >

Re: [Pharo-users] Equals and HashCode Builder

2017-10-06 Thread Vitor Medina Cruz
Stephane "Vitor why don't you take it as a small project to propose a solution for Pharo." I will try :) I like the idea of using a Trait. Em 6 de out de 2017 05:01, "Stephane Ducasse" escreveu: Here is what I extracted from older emails >From David Allouche in Pharo-dev to see if The ==hash

Re: [Pharo-users] Equals and HashCode Builder

2017-10-06 Thread Stephane Ducasse
Here is what I extracted from older emails >From David Allouche in Pharo-dev to see if The ==hash== method is used in Pharo to separate objects in bucket-based data structures. !! Property It must have one required property which is required data integrity: A. Objects that are equal accor

Re: [Pharo-users] Equals and HashCode Builder

2017-10-06 Thread Stephane Ducasse
Noury also proposed a trait to avoid to systematically have to implement hash. Vitor why don't you take it as a small project to propose a solution for Pharo. On Thu, Oct 5, 2017 at 6:34 PM, Vitor Medina Cruz wrote: > Yes, canEqual implementation also make #= be commutative. > > On Tue, Oct 3, 20

Re: [Pharo-users] Equals and HashCode Builder

2017-10-05 Thread Vitor Medina Cruz
Yes, canEqual implementation also make #= be commutative. On Tue, Oct 3, 2017 at 11:11 AM, Denis Kudriashov wrote: > > 2017-10-02 17:30 GMT+02:00 Denis Kudriashov : > >> >> 2017-10-02 17:13 GMT+02:00 Vitor Medina Cruz : >> >>> I am sorry, not species, but #isKindOf istead of #= to compare classe

Re: [Pharo-users] Equals and HashCode Builder

2017-10-03 Thread Denis Kudriashov
2017-10-02 17:30 GMT+02:00 Denis Kudriashov : > > 2017-10-02 17:13 GMT+02:00 Vitor Medina Cruz : > >> I am sorry, not species, but #isKindOf istead of #= to compare classes. >> > > It is bad idea. #= should be transitive. > Oh, I used wrong word, shame on me :). I tried to say commutative. > Ho

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Vitor Medina Cruz
Denis, That can be done with an canEqual implementation as described by http://www.artima.com/lejava/articles/equality.html. For this reason, it’s better to multiply successive fields by a constant > (e.g. shifting left by 2) before XORing them into the hash. But then, for > objects with lots of

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Prof. Andrew P. Black
> On 2 Oct 2017, at 16:37 , Sean P. DeNigris wrote: > > 2. #hash > ^ var1 hash bitXor: (var2 hash bitXor: var3 hash) > Is this implementation always safe? It's what I usually hand roll based on > what I've seen, but Andres Valloud wrote a whole (large) book on hashing, so > I've always wo

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Denis Kudriashov
2017-10-02 17:13 GMT+02:00 Vitor Medina Cruz : > I am sorry, not species, but #isKindOf istead of #= to compare classes. > It is bad idea. #= should be transitive. How you will generate it with isKindOf: logic? You need to know common parent. Also I not remember cases where I was needed two inst

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Vitor Medina Cruz
I am sorry, not species, but #isKindOf istead of #= to compare classes. On Mon, Oct 2, 2017 at 11:57 AM, Denis Kudriashov wrote: > > 2017-10-02 16:37 GMT+02:00 Sean P. DeNigris : > >> >> Two questions/comments about the generated code: >> 1. #= >> ... >> self class = anObject cla

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Denis Kudriashov
2017-10-02 16:37 GMT+02:00 Sean P. DeNigris : > > Two questions/comments about the generated code: > 1. #= > ... > self class = anObject class "should compare #species instead?" > ifFalse: [ ^ false ]. > ... > Typically, I've seen #species instead of #class

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Vitor Medina Cruz
I think it should have an option to generate with species (which I think should be the default). Also It would be nice if it could implement the solution for pitfall #4 described in http://www.artima.com/lejava/articles/equality.html On Mon, Oct 2, 2017 at 11:45 AM, Denis Kudriashov wrote: > 201

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Denis Kudriashov
2017-10-02 16:41 GMT+02:00 Sean P. DeNigris : > Denis Kudriashov wrote > > I just use RBGenerateEqualHashRefactoring for this: > > I added your answer to the Pharo wiki. Is this available through the UI? If > not, maybe it should be! > > As I know it not exists > > > - > Cheers, > Sean > --

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Denis Kudriashov
Hi Sean. I did not know about quality of generated hash function. But if I remember correctly the same code is generated for java using Eclipse or Idea. So it should be good enough. 2017-10-02 16:37 GMT+02:00 Sean P. DeNigris : > Denis Kudriashov wrote > > I just use RBGenerateEqualHashRefactori

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Sean P. DeNigris
Denis Kudriashov wrote > I just use RBGenerateEqualHashRefactoring for this: I added your answer to the Pharo wiki. Is this available through the UI? If not, maybe it should be! - Cheers, Sean -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Sean P. DeNigris
Denis Kudriashov wrote > I just use RBGenerateEqualHashRefactoring for this: > > r := RBGenerateEqualHashRefactoring className: MyClass variables: #(vars > which should be used in equal and hash). > r execute That is so cool! I shudder to think how many times I implemented just that by hand!!

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Vitor Medina Cruz
*in java, because this is a pain to do it each time.* *for us, maybe for the same… even if is a lot easier.* Yeah, and it is boring to implement that every time, especially because it is tricky to get it right sometimes. Another interesting thing I use in Java to test my equals and hash implement

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Stephane Ducasse
Publish it in a package and let us have a look. On Mon, Oct 2, 2017 at 9:53 AM, Jose San Leandro wrote: > Hi, > > I wrote a generator for that. Probably it makes no sense to publish it as > a standalone project. I tend to think code generation fits better in other > languages. > I can paste the

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Jose San Leandro
Hi, I wrote a generator for that. Probably it makes no sense to publish it as a standalone project. I tend to think code generation fits better in other languages. I can paste the relevant code here if needed. 2017-10-02 9:44 GMT+02:00 Esteban Lorenzano : > in java, because this is a pain to do

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Denis Kudriashov
Hi. I just use RBGenerateEqualHashRefactoring for this: r := RBGenerateEqualHashRefactoring className: MyClass variables: #(vars which should be used in equal and hash). r execute But it is a bit different. 2017-10-02 0:51 GMT+02:00 Vitor Medina Cruz : > Hello! > > Is there, in Pharo, builder

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Esteban Lorenzano
in java, because this is a pain to do it each time. for us, maybe for the same… even if is a lot easier. Esteban > On 2 Oct 2017, at 09:42, Stephane Ducasse wrote: > > Not that I know. > Because it can be a little project. > Now what is the key point to encapsulate this computation? > > On M

Re: [Pharo-users] Equals and HashCode Builder

2017-10-02 Thread Stephane Ducasse
Not that I know. Because it can be a little project. Now what is the key point to encapsulate this computation? On Mon, Oct 2, 2017 at 12:51 AM, Vitor Medina Cruz wrote: > Hello! > > Is there, in Pharo, builders for equals (=) and hash messages similar to: > https://commons.apache.org/proper/com