[Newbies] crossSum

David Shaffer cdshaffer at acm.org
Tue May 9 12:11:15 UTC 2006


Enrico Schwass wrote:

>Hello
>
>First of all. The creation of this mailinglist was a very good idea.
>Reading the original list I always felt wrong, because of the very high
>level of questions and ... yes answers. Thanks :)
>
>Anyway. I was looking for a crossSum Method for Integers.
>
>e.g. 251 crossSum (sometimes called checksum) should return 8
>
>1234 -> 10
>
>I couldnt find one with method finder. So I wrote one by myself.
>And a friend - also a smalltalk newbie - did another one.
>
>Probably both are not perfect.
>
>The first problem is: Where to put the new method? We decide to put it
>directly into Integer (arithmetic). There are no side effects, we guess.
>Are we right?
>  
>
Yes.  At some point (or maybe already) you might wonder how you can
maintain such class extensions.  If you are using ChangeSet's then it is
no problem, your new method is automatically added to your current CS. 
If you are using Monticello (recommended once you "really get going")
then you need to use a method category which corresponds to your package
name.  For example, suppose you create a Monticello package named
"MyProject" then you should put your extension to Integer into a method
category named "*MyProject" (case insensitive) so that Monticello knows
that it is part of the package.


>Second, we dont know the class library very well. It tooks 20 min to
>find the smalltalk equivalent to !=
>
>Its ~= for other newbies :)
>  
>
Yes, ouch.  A good Smalltalk book would help you a lot.  Have a look at:

http://www.iam.unibe.ch/~ducasse/FreeBooks.html

Most of these books are quite good and they will almost all introduce
you to the class library basics.  I like Sharp's book even if it has a
VisualWorks Smalltalk slant.  "Smalltalk with Style" is more about how
you should write code in Smalltalk rather than the Smalltalk language
itself so you might save it for your second book.


David



More information about the Beginners mailing list