Re: Re[2]: [Newbies] Adding method to Smallinteger class

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

Re: Re[2]: [Newbies] Adding method to Smallinteger class

David Mitchell-10
OK, Bert is having a little fun. Certainly good to learn that self is the default value.

But I wouldn't think of this as idiomatic smalltalk style.

I would prefer to follow "Interesting Return Value" [Beck]. I also factored out the return, since that is the same in both branches.

larger: anInteger
       ^ self > anInteger
               ifTrue: [self]
               ifFalse: [anInteger]



On Fri, Apr 23, 2010 at 4:39 PM, Bert Freudenberg <[hidden email]> wrote:
On 23.04.2010, at 23:19, Herbert König wrote:
>
> Hi Randal,
>
>
> RLS>   larger: anInteger
> RLS>   ^self max: anInteger
> RLS> Code re-use, bay-bee.
>
> true but couldn't resist to throw blocks at a newbie myself :-))

Sure, but two blocks are just too scary ;)
Much more fun to figure out why this works:

larger: anInteger
       anInteger > self ifTrue: [^ anInteger]

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners