|
Accessors: msg#00089lang.smalltalk.squeak.beginners
Hi Blake, In squeak we usually just leave the garbage for the maid to pick up. However: myCollection := nil. or myCollection := #() . will clear the collection. myCollection withAll: nil . leaves the collection its original size and resets contents. On accessors versus raw IVars. its a matter of programmer choice. If the data is hidden from other classes it can be handled by using just the iVars within the class w/o an accessor. Your probably about ready for Kent Beck's book "Smalltalk: best programming pattern practices." Which will answer a lot of the questions you are about to ask. If you try to do the "simplest thing that might possibly work." Then you would probably start with the ivars and switch over to using accessors when there becomes a need. *** > [Newbies] Accessors > > Blake blake at kingdomrpg.com > Mon Mar 12 01:36:12 UTC 2007 wrote: > > I've been using accessors for every instance variable, > and even using them > internally. > > I have to admit, because of the need to preface every > method call with > "self", it makes the code look less clean. > > I've also ended up with what seems to be an odd > construct: > > clear > self myCollection removeAll: self myCollection > Go reread the comment for #removeAll I believe you will find it does not do what you wish. One of the necessary ways to learn squeak is to try out your ideas in a work space. Try: myCollection := OrderedCollection new add: 4 ; add: 3 ; add: 2 ; add: 1 ; yourself. myCollection removeAll: myCollection . and see what you get. See if you can figure out why. Then RTFM. Read the fine manual of Kent Beck. And RTFC. Read the fine comments (or code) in squeak itself. > Part of this is the self thing: > > myCollection removeAll: myCollection > > and the other part is...I guess, not being able to find > a "clear" > > Thanks for all the feedback guys. Very helpful. > > I've been too lazy with my Smalltalk (thinking) in the > past and this has > helped a lot. > *** Yours in service, --Jerome Peace ____________________________________________________________________________________ The fish are biting. Get more visitors on your site using Yahoo! Search Marketing. http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Accessors, Blake |
|---|---|
| Next by Date: | Re: Accessors, Blake |
| Previous by Thread: | Accessors, Blake |
| Next by Thread: | Re: Accessors, Blake |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |