another "best practices" question - inject

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

another "best practices" question - inject

Mark Volkmann
The "Inject:Into:" pattern in "Smalltalk Best Practice Patterns" says  
"Call the block arguments sum and each." That seems crazy! Why would I  
name the first argument "sum" if I've trying to do something other  
than sum the values? The example the book gives is the following.

^self children
        inject: 0
        into: [:sum :each | sum max: each]

I think I'd do this.

^self children
        inject: 0
        into: [:maximum :each | maximum max: each]

---
Mark Volkmann




_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: another "best practices" question - inject

David Mitchell-10
Yep, that does seem crazy. Will reread that tonight!

On Sun, Nov 2, 2008 at 2:54 PM, Mark Volkmann <[hidden email]> wrote:

> The "Inject:Into:" pattern in "Smalltalk Best Practice Patterns" says "Call
> the block arguments sum and each." That seems crazy! Why would I name the
> first argument "sum" if I've trying to do something other than sum the
> values? The example the book gives is the following.
>
> ^self children
>        inject: 0
>        into: [:sum :each | sum max: each]
>
> I think I'd do this.
>
> ^self children
>        inject: 0
>        into: [:maximum :each | maximum max: each]
>
> ---
> Mark Volkmann
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners