Re: [Pharo-users] Generate equality

2018-02-09 Thread Denis Kudriashov
I will add it to Calypso.
I use it often.

2018-02-08 17:23 GMT+03:00 Herbert Vojčík :

>
> Stephane Ducasse wrote:
>
>> http://smalltalkhub.com/#!/~CAR/ReusableBricks/packages/Equals
>>
>
> Ah. It uses trait that does it dynamically.
>
> Good to know, usable for some more dynamic scenarios; but here I wanted
> something more explicit a la existing "generate xxx", so I went for
> Alistair's suggestion, so it was just a matter of Playground and:
>
> (RBGenerateEqualHashRefactoring className: PharktSymbol variables:
> #(baseAsset quoteAsset)) execute
>
> Thanks.
>
> (btw, it would be nice if that was actually in a menu; but if Nautilus if
> phased out, at least in Calypso in Pharo 7 :-) )
>
> Herby
>
>
> On Thu, Feb 8, 2018 at 12:47 PM, Herbert Vojčík  wrote:
>>
>>>
>>> Alistair Grant wrote:
>>>
 Hi Herby,

 On 8 February 2018 at 03:10, Herbert Vojčík   wrote:

> 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.
>

 The refactoring browser is already capable of generating #= and #hash:

>>>
>>> Now somebody tell me it actually is there in the Nautilus menu, I just
>>> did
>>> not find it. Which would be the best outcome, save making myself
>>> ridiculous
>>> online... :-)
>>>
>>>
>>> | r |

 r := RBGenerateEqualHashRefactoring
   className: MyClass
   variables: #(vars which should be used in equal and hash).
 r execute


 HTH,
 Alistair


>>
>


Re: [Pharo-users] Generate equality

2018-02-08 Thread Herbert Vojčík


Stephane Ducasse wrote:

http://smalltalkhub.com/#!/~CAR/ReusableBricks/packages/Equals


Ah. It uses trait that does it dynamically.

Good to know, usable for some more dynamic scenarios; but here I wanted 
something more explicit a la existing "generate xxx", so I went for 
Alistair's suggestion, so it was just a matter of Playground and:


(RBGenerateEqualHashRefactoring className: PharktSymbol variables: 
#(baseAsset quoteAsset)) execute


Thanks.

(btw, it would be nice if that was actually in a menu; but if Nautilus 
if phased out, at least in Calypso in Pharo 7 :-) )


Herby


On Thu, Feb 8, 2018 at 12:47 PM, Herbert Vojčík  wrote:


Alistair Grant wrote:

Hi Herby,

On 8 February 2018 at 03:10, Herbert Vojčík   wrote:

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.


The refactoring browser is already capable of generating #= and #hash:


Now somebody tell me it actually is there in the Nautilus menu, I just did
not find it. Which would be the best outcome, save making myself ridiculous
online... :-)



| r |

r := RBGenerateEqualHashRefactoring
  className: MyClass
  variables: #(vars which should be used in equal and hash).
r execute


HTH,
Alistair







Re: [Pharo-users] Generate equality

2018-02-08 Thread Stephane Ducasse
http://smalltalkhub.com/#!/~CAR/ReusableBricks/packages/Equals

On Thu, Feb 8, 2018 at 12:47 PM, Herbert Vojčík  wrote:
>
>
> Alistair Grant wrote:
>>
>> Hi Herby,
>>
>> On 8 February 2018 at 03:10, Herbert Vojčík  wrote:
>>>
>>> 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.
>>
>>
>> The refactoring browser is already capable of generating #= and #hash:
>
>
> Now somebody tell me it actually is there in the Nautilus menu, I just did
> not find it. Which would be the best outcome, save making myself ridiculous
> online... :-)
>
>
>> | r |
>>
>> r := RBGenerateEqualHashRefactoring
>>  className: MyClass
>>  variables: #(vars which should be used in equal and hash).
>> r execute
>>
>>
>> HTH,
>> Alistair
>>
>



Re: [Pharo-users] Generate equality

2018-02-08 Thread Herbert Vojčík



Alistair Grant wrote:

Hi Herby,

On 8 February 2018 at 03:10, Herbert Vojčík  wrote:

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.


The refactoring browser is already capable of generating #= and #hash:


Now somebody tell me it actually is there in the Nautilus menu, I just 
did not find it. Which would be the best outcome, save making myself 
ridiculous online... :-)



| r |

r := RBGenerateEqualHashRefactoring
 className: MyClass
 variables: #(vars which should be used in equal and hash).
r execute


HTH,
Alistair





Re: [Pharo-users] Generate equality

2018-02-08 Thread Alistair Grant
Hi Herby,

On 8 February 2018 at 03:10, Herbert Vojčík  wrote:
> 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.

The refactoring browser is already capable of generating #= and #hash:


| r |

r := RBGenerateEqualHashRefactoring
className: MyClass
variables: #(vars which should be used in equal and hash).
r execute


HTH,
Alistair



Re: [Pharo-users] Generate equality

2018-02-08 Thread herby


On February 8, 2018 5:07:03 AM GMT+01:00, "Hernán Morales Durand" 
 wrote:
>Hi Herbert,
>
>How the "generate equality" behavior would be the default?
>Mechanically = non-interactive?

Like “generate accessors”. So interactively, on demand. Of course.

I tried to draw that analogy on original post, but probably wasn't writing it 
down clearly enough.

Herby
>
>Cheers,
>
>Hernán
>
>
>2018-02-07 13:10 GMT-03:00 Herbert Vojčík :
>> 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
>>



Re: [Pharo-users] Generate equality

2018-02-08 Thread Stephane Ducasse
Guys you should really check what noury did :)



On Thu, Feb 8, 2018 at 5:07 AM, Hernán Morales Durand
 wrote:
> Hi Herbert,
>
> How the "generate equality" behavior would be the default?
> Mechanically = non-interactive?
>
> Cheers,
>
> Hernán
>
>
> 2018-02-07 13:10 GMT-03:00 Herbert Vojčík :
>> 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
>>
>



Re: [Pharo-users] Generate equality

2018-02-07 Thread Hernán Morales Durand
Hi Herbert,

How the "generate equality" behavior would be the default?
Mechanically = non-interactive?

Cheers,

Hernán


2018-02-07 13:10 GMT-03:00 Herbert Vojčík :
> 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
>



Re: [Pharo-users] Generate equality

2018-02-07 Thread Richard Sargent
On Wed, Feb 7, 2018 at 12:51 PM, Herbert Vojčík  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:
>>
>>> 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:

 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

>>>
>>
>


Re: [Pharo-users] Generate equality

2018-02-07 Thread Herbert Vojčík



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:

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)...


Herby


Norbert


Am 07.02.2018 um 17:10 schrieb Herbert Vojčík:

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






Re: [Pharo-users] Generate equality

2018-02-07 Thread Esteban A. Maringolo
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 :
> I think that implementing = and hash is almost always wrong. So I guess the 
> answer is no :)
>
> Norbert
>
>> Am 07.02.2018 um 17:10 schrieb Herbert Vojčík :
>>
>> 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
>



Re: [Pharo-users] Generate equality

2018-02-07 Thread Norbert Hartl
I think that implementing = and hash is almost always wrong. So I guess the 
answer is no :)

Norbert

> Am 07.02.2018 um 17:10 schrieb Herbert Vojčík :
> 
> 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



Re: [Pharo-users] Generate equality

2018-02-07 Thread Stephane Ducasse
Noury proposed a traits for that long time ago and it looked smart.
I do not remember where.

On Wed, Feb 7, 2018 at 5:10 PM, Herbert Vojčík  wrote:
> 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
>



Re: [Pharo-users] Generate equality

2018-02-07 Thread Herbert Vojčík

This does not look like the answer to my question. :-/

Ok, to rephrase:

Would you find it useful to have "generate equality" which generates #= 
and #hash for a class?


Herby

P.S.: I know there is "generate accessors". I mentioned it as "a thing 
which is there, and from which one can get inspiration".


Peter Uhnák wrote:

 > generate accessors

there is option to generate accessors (right click on class)... but I
find it rarely useful after initial setup (having accessors for all
instance variables is rarely needed, and it is annoying to uncheck all
the time).
In the latter scenario I have a small hack (startup script) that adds
the option to instance variable (works with slot class layouts only)
suggestions menu (not updated for calypso yet...
https://github.com/peteruhnak/pharo-scripts/blob/master/config/6.0/suggestions-for-inst-vars.st
)

for initialize, Nautilus had some shortcuts to generate code which you
can try
https://gist.github.com/peteruhnak/d9ee54f67d88b20ba85618e189b15669#generating

Peter

On Wed, Feb 7, 2018 at 5:10 PM, Herbert Vojčík > wrote:

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






Re: [Pharo-users] Generate equality

2018-02-07 Thread Peter Uhnák
>  generate accessors

there is option to generate accessors (right click on class)... but I find
it rarely useful after initial setup (having accessors for all instance
variables is rarely needed, and it is annoying to uncheck all the time).
In the latter scenario I have a small hack (startup script) that adds the
option to instance variable (works with slot class layouts only)
suggestions menu (not updated for calypso yet...
https://github.com/peteruhnak/pharo-scripts/blob/master/config/6.0/suggestions-for-inst-vars.st
)

for initialize, Nautilus had some shortcuts to generate code which you can
try
https://gist.github.com/peteruhnak/d9ee54f67d88b20ba85618e189b15669#generating

Peter

On Wed, Feb 7, 2018 at 5:10 PM, Herbert Vojčík  wrote:

> 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
>
>


[Pharo-users] Generate equality

2018-02-07 Thread Herbert Vojčík

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