On Thu, Jan 21, 2016 at 6:18 PM, Henrik Nergaard <henrik.nergaard@uia.no> wrote:
What about something like this?
I'm not very familiar with hashing. Could you explain the benefit of this approach? cheers -ben
^self species hash hashComposer add: leftFraction; add: leftOffset; add: topFraction; add: topOffset; add: rightOffset; add: bottomFraction; add: bottomOffset
HashComposer>>#add: anObject
^hash := (hash + anObject hash) hashMultiply
Best regards, Henrik
-----Original Message----- From: Pharo-dev [mailto:pharo-dev-bounces@lists.pharo.org] On Behalf Of Stephan Eggermont Sent: Wednesday, January 13, 2016 8:34 PM To: pharo-dev@lists.pharo.org Subject: Re: [Pharo-dev] Bad layoutFrame>>#hash
On 13-01-16 18:38, David Allouche wrote:
Why did you use a single expression instead of using a temporary variable? I find it harder to understand.
I did find it very slightly easier to understand. It is not a strong opinion however.
The ideomatic smalltalk would be
^#(leftFraction leftOffset topFraction topOffset rightFraction rightOffset bottomFraction bottomOffset) inject: self species hash into: [:hashValue :selector | (hashValue + self perform: selector) hashMultiply ]
but that would be slower.
I would be tempted to add a binary message
Integer>>+** aNumber ^(aNumber +self hash) hashMultiply
(I'd prefer +#*, but that doesn't parse)
hash ^self species hash +** leftFraction +** leftOffset +** topFraction +** topOffset +** rightFraction +** rightOffset +** bottomFraction +** bottomOffset
Stephan