Smalltalk is a Mystery to Me

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

Smalltalk is a Mystery to Me

Tcykgreis
I have had a curiosity about Smalltalk for many years so I recently downloaded and installed Squeak. That's when the trouble began. I have written applications that deal bridge hands and either display the hands on screen or save them in a couple of different formats. I originally wrote the 'words' in Forth. I later tried Ruby and rewrote most of the programs in Ruby. I did it as a learning experience. I sat out to do the same thing in Squeak, again as a learning experience, but have made virtually no progress. I create the class 'Bridge' with the subclass of dealer. I try to initialize by filling a byteArray with 52 numbers, 0 through 51. I tended to create additional methods to shuffle and deal the cards to four more byte arrays named north, east, south, and west. Eventually I will need another method to "stack the deck." I will also need a counter to keep track of the deal number.
 
I can't get started, and I mean zero progress, because I can't create and load deck. It seems like the documentation is never quit up to date. I read about curly braces and tried deck := {0. 1. 2. ... }. When I try to accept it, first deck is questioned and then after deck I get something about not expecting anything else.
I know there is a word 'asByteArray:' and I assume a number would specify the size of the array but nowhere can I find anything about the order in which the information should be provided. I tried deck asByteArray: 52 but I don't know if it worked. If it did work, how do I load the bytes into it? How do I look at a byte in a particular location in the array? Can I remove a byte from position x and/or insert a byte at position y and everything moves to accommodate the change.
 
In Forth and Ruby, I was able to store the hands as a 2D bit array, 4 suits and 13 bits. If the card was present the bit was set. When I dealt the cards, the appropriate bits were set.. This worked really well. The suits came out already sorted. The strength of a suit turned out to be related to the value stored for the suit. The number of cards in the suit could be found by counting set bits. I have yet to find bit-manipulating words in Squeak/Smalltalk.
 
As an aside, the least number of bits that must be used to store a complete deal is 104 or 13 bytes. The bits are arranged in 52 2-bit groups. The position in the array represents the value of the card and the bits determine which hands gets the card represented by that position. When you shuffle the 2-bit groups must be kept in tact. I could easily do this in Forth but could not do it in Ruby. If you are going to save a few million hands, it is nice to be able to do so in this most compact form.
 
If I could just figure out where to find the answers to these beginner question, I would really appreciate it. It would also be nice if I could see some examples of these methods.
 
Charlie
 
 




It's only a deal if it's where you want to go. Find your travel deal here.

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

Re: Smalltalk is a Mystery to Me

Herbert König
Hello Charlie,

nobody replied yet, so for a start:

Tac> I have had a curiosity about Smalltalk for many years so I
Tac> recently downloaded and installed Squeak. That's when the trouble
Tac> began. I have written applications that deal bridge hands and
Tac> either display the hands on screen or save them in a couple of
Tac> different formats. I originally wrote the 'words' in Forth. I

while in Smalltalk you create classes but most importantly sent
messages between objects. That's quite a difference.

Tac> In Forth and Ruby, I was able to store the hands as a 2D
Tac> bit array, 4 suits and 13 bits. If the card was present the bit
Tac> was set. When I dealt the cards, the appropriate bits were set..

If you'll try it this way in the end you'll find Smalltalk is an
awkward language for that kind of program.

You need to think about Bridge in Bridge terms and then this will
translate nicely into Smalltalk objects and methods.

I suggest you Google for Squeak by example (free Book) so you get a
feel for Smalltalk

Sorry I know noting about Bridge but when you can show most parts of
that Smalltalk program to a bridge player and he will have no problem
following what the program does then you wrote a good Smalltalk
program. Bits in Arrays of Bytes don't fall into this category.


Hope someone who knows about Bridge chimes in.

--
Cheers,

Herbert  

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

Re: Smalltalk is a Mystery to Me

Tapple Gao
In reply to this post by Tcykgreis
On Thu, Aug 21, 2008 at 08:30:25PM -0400, [hidden email] wrote:

> I can't get started, and I mean zero progress, because I can't create and  
> load deck. It seems like the documentation is never quit up to date. I read  
> about curly braces and tried deck := {0. 1. 2. ... }. When I try to accept it,  
> first deck is questioned and then after deck I get something about not
> expecting  anything else.
> I know there is a word 'asByteArray:' and I assume a number would specify  
> the size of the array but nowhere can I find anything about the order in which  
> the information should be provided. I tried deck asByteArray: 52 but I don't  
> know if it worked. If it did work, how do I load the bytes into it? How do I  
> look at a byte in a particular location in the array? Can I remove a byte from
>  position x and/or insert a byte at position y and everything moves to  
> accommodate the change.

In a workspace, try typing these and press alt-p (print it):

#(2 3 5) at: 1. "2"
#(2 3 5) at: 2. "3"
#(2 3 5) at: 3 put: 7. "#(2 3 7)"

2 bitAnd: 3. "2"
2 bitOr:  3. "3"
2 bitXor: 3. "1"

No, you cannot insert/remove elements from Arrays. They are
fixed length objects. Use OrderedCollection if you want that.

See http://squeak.org/Documentation. I think the terse guide to
squeak will be especially helpful to you:
http://wiki.squeak.org/squeak/5699

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

Re: Smalltalk is a Mystery to Me

Nicolas Cellier-3
In reply to this post by Tcykgreis
[hidden email] a écrit :

> I have had a curiosity about Smalltalk for many years so I recently
> downloaded and installed Squeak. That's when the trouble began. I have
> written applications that deal bridge hands and either display the hands
> on screen or save them in a couple of different formats. I originally
> wrote the 'words' in Forth. I later tried Ruby and rewrote most of the
> programs in Ruby. I did it as a learning experience. I sat out to do the
> same thing in Squeak, again as a learning experience, but have made
> virtually no progress. I create the class 'Bridge' with the subclass of
> dealer. I try to initialize by filling a byteArray with 52 numbers, 0
> through 51. I tended to create additional methods to shuffle and deal
> the cards to four more byte arrays named north, east, south, and west.
> Eventually I will need another method to "stack the deck." I will also
> need a counter to keep track of the deal number.
>  
> I can't get started, and I mean zero progress, because I can't create
> and load deck. It seems like the documentation is never quit up to date.
> I read about curly braces and tried deck := {0. 1. 2. ... }. When I try
> to accept it, first deck is questioned and then after deck I get
> something about not expecting anything else.

What kind of Object is a Bridge? to me it sounds more like a namespace
than an Object.
What kind of object is a Dealer? Maybe you mean a Deal?
What are the instance variable of your class?
What are its main methods (the messages than Dealer will respond to) you
want to implement?

You really have to think in term of Objects and messages, otherwise your
Smalltalk experience won't be that nice.

Maybe you want to create an initialize method in Dealer, assuming deck
is an instance variable:

initialize
        deck := (1 to: 52) asOrderedCollection shuffled.

Then, when you create a Dealer object (Dealer new), its instance
variable will be initialized.

> I know there is a word 'asByteArray:' and I assume a number would
> specify the size of the array but nowhere can I find anything about the
> order in which the information should be provided. I tried deck
> asByteArray: 52 but I don't know if it worked. If it did work, how do I
> load the bytes into it? How do I look at a byte in a particular location
> in the array? Can I remove a byte from position x and/or insert a byte
> at position y and everything moves to accommodate the change.
>  

| ba |
ba := ByteArray new: 52. "Create a ByteArray with 52 bytes"
ba at: 5 put: 23. "set the fith element to 23"

(1 to: 52) asByteArray. "Try to evaluate this..."

(1 to: 52) asByteArray shuffled. "That might be of interest"

If you want to insert and remove, I recommend you begin with an
OrderedCollection. OrderedCollection are growable and support adding and
removing elements easily (you'll have to browse existing messages or get
help from Squeak by example book which is excellent for beginners).

An Array has a fixed size and must be copied if you want to
insert/remove elements.
You can inquire about #copyReplaceFrom:to:with:

ba := ba copyReplaceFrom: 3 to: 4 with: ByteArray new. "remove third and
fourth elements"

ba := ba copyReplaceFrom: 3 to: 2 with: {11. 22.} asByteArray. "insert
11 and 22 at third and fourth position"

> In Forth and Ruby, I was able to store the hands as a 2D bit array, 4
> suits and 13 bits. If the card was present the bit was set. When I dealt
> the cards, the appropriate bits were set.. This worked really well. The
> suits came out already sorted. The strength of a suit turned out to be
> related to the value stored for the suit. The number of cards in the
> suit could be found by counting set bits. I have yet to find
> bit-manipulating words in Squeak/Smalltalk.
>  
> As an aside, the least number of bits that must be used to store a
> complete deal is 104 or 13 bytes. The bits are arranged in 52 2-bit
> groups. The position in the array represents the value of the card and
> the bits determine which hands gets the card represented by that
> position. When you shuffle the 2-bit groups must be kept in tact. I
> could easily do this in Forth but could not do it in Ruby. If you are
> going to save a few million hands, it is nice to be able to do so in
> this most compact form.
>

I strongly recommend you write a non optimized version to begin with.
Squeak has enough support for collection to shuffle sort add remove
select reject etc...

Then only when you get used to objects and messages, you should inquire
about optimizing space with bits in bit arrays.

Note that it's absolutely doable in Squeak, but you'll may have to write
some of the base methods. I think Yoshiki Oshima have quite an advanced
implementation of BitArray, take a look at SqueakMap (from World menu
Open...).


> If I could just figure out where to find the answers to these beginner
> question, I would really appreciate it. It would also be nice if I could
> see some examples of these methods.
>  
> Charlie
>  
>  
>

Maybe a look at free book Squeak by Example would be a good start to get
acquainted to Smalltalk.

Cheers

>
>
> ------------------------------------------------------------------------
> It's only a deal if it's where /you/ want to go. Find your travel deal
> *here* <http://information.travel.aol.com/deals?ncid=aoltrv00050000000047>.
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

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

Re: Re: Smalltalk is a Mystery to Me

David Zmick
Squeak by Example is a great FREE book you can download.  I use it as a kind of reference sometimes when programming, I think you should check it out. http://squeakbyexample.org

On Fri, Aug 22, 2008 at 12:18 PM, nicolas cellier <[hidden email]> wrote:
[hidden email] a écrit :

I have had a curiosity about Smalltalk for many years so I recently downloaded and installed Squeak. That's when the trouble began. I have written applications that deal bridge hands and either display the hands on screen or save them in a couple of different formats. I originally wrote the 'words' in Forth. I later tried Ruby and rewrote most of the programs in Ruby. I did it as a learning experience. I sat out to do the same thing in Squeak, again as a learning experience, but have made virtually no progress. I create the class 'Bridge' with the subclass of dealer. I try to initialize by filling a byteArray with 52 numbers, 0 through 51. I tended to create additional methods to shuffle and deal the cards to four more byte arrays named north, east, south, and west. Eventually I will need another method to "stack the deck." I will also need a counter to keep track of the deal number.
 I can't get started, and I mean zero progress, because I can't create and load deck. It seems like the documentation is never quit up to date. I read about curly braces and tried deck := {0. 1. 2. ... }. When I try to accept it, first deck is questioned and then after deck I get something about not expecting anything else.

What kind of Object is a Bridge? to me it sounds more like a namespace than an Object.
What kind of object is a Dealer? Maybe you mean a Deal?
What are the instance variable of your class?
What are its main methods (the messages than Dealer will respond to) you want to implement?

You really have to think in term of Objects and messages, otherwise your Smalltalk experience won't be that nice.

Maybe you want to create an initialize method in Dealer, assuming deck is an instance variable:

initialize
       deck := (1 to: 52) asOrderedCollection shuffled.

Then, when you create a Dealer object (Dealer new), its instance variable will be initialized.


I know there is a word 'asByteArray:' and I assume a number would specify the size of the array but nowhere can I find anything about the order in which the information should be provided. I tried deck asByteArray: 52 but I don't know if it worked. If it did work, how do I load the bytes into it? How do I look at a byte in a particular location in the array? Can I remove a byte from position x and/or insert a byte at position y and everything moves to accommodate the change.
 

| ba |
ba := ByteArray new: 52. "Create a ByteArray with 52 bytes"
ba at: 5 put: 23. "set the fith element to 23"

(1 to: 52) asByteArray. "Try to evaluate this..."

(1 to: 52) asByteArray shuffled. "That might be of interest"

If you want to insert and remove, I recommend you begin with an OrderedCollection. OrderedCollection are growable and support adding and removing elements easily (you'll have to browse existing messages or get help from Squeak by example book which is excellent for beginners).

An Array has a fixed size and must be copied if you want to insert/remove elements.
You can inquire about #copyReplaceFrom:to:with:

ba := ba copyReplaceFrom: 3 to: 4 with: ByteArray new. "remove third and fourth elements"

ba := ba copyReplaceFrom: 3 to: 2 with: {11. 22.} asByteArray. "insert 11 and 22 at third and fourth position"


In Forth and Ruby, I was able to store the hands as a 2D bit array, 4 suits and 13 bits. If the card was present the bit was set. When I dealt the cards, the appropriate bits were set.. This worked really well. The suits came out already sorted. The strength of a suit turned out to be related to the value stored for the suit. The number of cards in the suit could be found by counting set bits. I have yet to find bit-manipulating words in Squeak/Smalltalk.
 As an aside, the least number of bits that must be used to store a complete deal is 104 or 13 bytes. The bits are arranged in 52 2-bit groups. The position in the array represents the value of the card and the bits determine which hands gets the card represented by that position. When you shuffle the 2-bit groups must be kept in tact. I could easily do this in Forth but could not do it in Ruby. If you are going to save a few million hands, it is nice to be able to do so in this most compact form.


I strongly recommend you write a non optimized version to begin with.
Squeak has enough support for collection to shuffle sort add remove select reject etc...

Then only when you get used to objects and messages, you should inquire about optimizing space with bits in bit arrays.

Note that it's absolutely doable in Squeak, but you'll may have to write some of the base methods. I think Yoshiki Oshima have quite an advanced implementation of BitArray, take a look at SqueakMap (from World menu Open...).



If I could just figure out where to find the answers to these beginner question, I would really appreciate it. It would also be nice if I could see some examples of these methods.
 Charlie
  

Maybe a look at free book Squeak by Example would be a good start to get acquainted to Smalltalk.

Cheers



------------------------------------------------------------------------
It's only a deal if it's where /you/ want to go. Find your travel deal *here* <http://information.travel.aol.com/deals?ncid=aoltrv00050000000047>.


------------------------------------------------------------------------


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

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



--
David Zmick
/dz0004455\
http://dz0004455.googlepages.com
http://dz0004455.blogspot.com

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

Re: Smalltalk is a Mystery to Me

Edgar J. De Cleene
In reply to this post by Tcykgreis



El 8/21/08 9:30 PM, "[hidden email]" <[hidden email]> escribió:

> I have had a curiosity about Smalltalk for many years so I recently downloaded
> and installed Squeak. That's when the trouble began. I have written
> applications that deal bridge hands and either display the hands on screen or
> save them in a couple of different formats. I originally wrote the 'words' in
> Forth. I later tried Ruby and rewrote most of the programs in Ruby. I did it
> as a learning experience. I sat out to do the same thing in Squeak, again as a
> learning experience, but have made virtually no progress. I create the class
> 'Bridge' with the subclass of dealer. I try to initialize by filling a
> byteArray with 52 numbers, 0 through 51. I tended to create additional methods
> to shuffle and deal the cards to four more byte arrays named north, east,
> south, and west. Eventually I will need another method to "stack the deck." I
> will also need a counter to keep track of the deal number.
>  
> I can't get started, and I mean zero progress, because I can't create and load
> deck. It seems like the documentation is never quit up to date. I read about
> curly braces and tried deck := {0. 1. 2. ... }. When I try to accept it, first
> deck is questioned and then after deck I get something about not expecting
> anything else.
> I know there is a word 'asByteArray:' and I assume a number would specify the
> size of the array but nowhere can I find anything about the order in which the
> information should be provided. I tried deck asByteArray: 52 but I don't know
> if it worked. If it did work, how do I load the bytes into it? How do I look
> at a byte in a particular location in the array? Can I remove a byte from
> position x and/or insert a byte at position y and everything moves to
> accommodate the change.
>  
> In Forth and Ruby, I was able to store the hands as a 2D bit array, 4 suits
> and 13 bits. If the card was present the bit was set. When I dealt the cards,
> the appropriate bits were set.. This worked really well. The suits came out
> already sorted. The strength of a suit turned out to be related to the value
> stored for the suit. The number of cards in the suit could be found by
> counting set bits. I have yet to find bit-manipulating words in
> Squeak/Smalltalk.
>  
> As an aside, the least number of bits that must be used to store a complete
> deal is 104 or 13 bytes. The bits are arranged in 52 2-bit groups. The
> position in the array represents the value of the card and the bits determine
> which hands gets the card represented by that position. When you shuffle the
> 2-bit groups must be kept in tact. I could easily do this in Forth but could
> not do it in Ruby. If you are going to save a few million hands, it is nice to
> be able to do so in this most compact form.
>  
> If I could just figure out where to find the answers to these beginner
> question, I would really appreciate it. It would also be nice if I could see
> some examples of these methods.
>  
> Charlie
>  

I see fellows  with only Smalltalk as background try to help.
The book they said, Squeak by Example, could be found and downloaded here
http://squeakbyexample.org/

I began my journey in the amazing Smalltalk/Squeak world six years ago,
coming from Pascal, Omnis 3 and the old beloved Mac Toolbox as only
background, so I understand you.

A book nobody tell you is The CRC Card Book by David Bellin and Susan
Simone.
Here you could learn to start to think in Objects, messages, collaborations
, etc.
When you have your Bridge working on paper (the cards full with
collaborations and messages), you could translate to Squeak.

If you try the wrong way (I do in my first six months) of doing same as you
do in procedural programming, eventually the light turn on and illuminate
the darkness.

But could be a long and frustrating experience.

Edgar




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

Re: Smalltalk is a Mystery to Me

Marcin Tustin
In reply to this post by Tcykgreis
On Fri, Aug 22, 2008 at 1:30 AM, <[hidden email]> wrote:
I have had a curiosity about Smalltalk for many years so I recently downloaded and installed Squeak. That's when the trouble began. I have written applications that deal bridge hands and either display the hands on screen or save them in a couple of different formats. I originally wrote the 'words' in Forth. I later tried Ruby and rewrote most of the programs in Ruby. I did it as a learning experience. I sat out to do the same thing in Squeak, again as a learning experience, but have made virtually no progress. I create the class 'Bridge' with the subclass of dealer. I try to initialize by filling a byteArray with 52 numbers, 0 through 51.

Woah...what? This doesn't really make any sense.
 
I tended to create additional methods to shuffle and deal the cards to four more byte arrays named north, east, south, and west. Eventually I will need another method to "stack the deck." I will also need a counter to keep track of the deal number.
 
I can't get started, and I mean zero progress, because I can't create and load deck. It seems like the documentation is never quit up to date. I read about curly braces and tried deck := {0. 1. 2. ... }. When I try to accept it, first deck is questioned and then after deck I get something about not expecting anything else.

This is because deck is undeclared, and then because you have a syntax error.
 
I know there is a word 'asByteArray:' and I assume a number would specify the size of the array but nowhere can I find anything about the order in which the information should be provided. I tried deck asByteArray: 52 but I don't know if it worked. If it did work, how do I load the bytes into it? How do I look at a byte in a particular location in the array? Can I remove a byte from position x and/or insert a byte at position y and everything moves to accommodate the change.

First of all, are you familiar with the syntax?

Squeak by example will help guide you through looking at classes, and seeing what methods they have etc.
 
In Forth and Ruby, I was able to store the hands as a 2D bit array, 4 suits and 13 bits. If the card was present the bit was set. When I dealt the cards, the appropriate bits were set.. This worked really well. The suits came out already sorted. The strength of a suit turned out to be related to the value stored for the suit. The number of cards in the suit could be found by counting set bits. I have yet to find bit-manipulating words in Squeak/Smalltalk.
 
As an aside, the least number of bits that must be used to store a complete deal is 104 or 13 bytes. The bits are arranged in 52 2-bit groups. The position in the array represents the value of the card and the bits determine which hands gets the card represented by that position. When you shuffle the 2-bit groups must be kept in tact. I could easily do this in Forth but could not do it in Ruby. If you are going to save a few million hands, it is nice to be able to do so in this most compact form.
 
If I could just figure out where to find the answers to these beginner question, I would really appreciate it. It would also be nice if I could see some examples of these methods.
 
Charlie
 

I would recommend that you create a card class, with a member variable that represents the suit (probably as a symbol) and a second member variable that represents the card in the suit. Create a class method that returns new instances (eventually have it throw an exception if something out of the range of what is acceptable is created) and have a second class method that creates a collection of cards that contains all the cards, in order. You can use the methods on the appropriate collection to shuffle it.

Once you've built something working on that, you can try to optimise storage, either on disk or in memory.

 




It's only a deal if it's where you want to go. Find your travel deal here.

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



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

Re: Smalltalk is a Mystery to Me

tblanchard
In reply to this post by Tcykgreis

On Aug 21, 2008, at 5:30 PM, [hidden email] wrote:

I try to initialize by filling a byteArray with 52 numbers, 0 through 51. I tended to create additional methods to shuffle and deal the cards to four more byte arrays named north, east, south, and west. Eventually I will need another method to "stack the deck." I will also need a counter to keep track of the deal number.

Fundamentally, I would say you are working at too low of a level.  Using numbers to represent cards is an implementation detail you used in your previous implementations, but in Smalltalk we work at a higher level.

A deck, hand, pile, all can be implemented as just an OrderedCollection.  You might start with a Deal or BridgeRound or something.  It might have some methods like:

initialize
| hands deck |
deck := Card bridgeDeck shuffled asOrderedCollection. "just like english"
north := OrderedCollection new.
south := OrderedCollection new.
east := OrderedCollection new.
west := OrderedCollection new.
trick := OrderedCollection new.

"deal the whole deck"
hands := (Array with: north with: east with: south with: west).
[deck isEmpty] whileFalse:  
[hands do: [:hand | deck ifNotEmptyDo: [:d | hand add: d removeFirst]]].

which sets up all the collections of cards in a typical bridge deal.  trick is the middle pile in the table.  Maybe you need it, maybe not.

Card is an object that contains your numerical value and has some methods that return the suit and rank.  A class method could return an array of 52.  

bridgeDeck

^(Interval from: 0 to: 51) collect: [:i | self code: i]

code: aNumber

^self new code: aNumber

some useful instance methods on card might be

rank
^(code // 4) + 1

suit
^(code \\ 4) + 1

printOn: aStream

| ranks suits | 
ranks := #( Ace 2 3 4 5 6 7 8 9 10 Jack Queen King ).
suits := #( Clubs Hearts Diamonds Spades ).

aStream 
nextPutAll: (ranks at: self rank) asString; 
nextPutAll: ' of ';
nextPutAll: (suits at: self suit) asString.

which will cause each card to be displayed in the form 'Ace of Clubs' or whatever.

Down the road, maybe you want to keep more information about players, like what tricks they've taken, so replace the OrderedCollections with a BridgePlayer with more instance variables etc...

Hopefully that will get you going.

-Todd Blanchard

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

Re: Smalltalk is a Mystery to Me

Randal L. Schwartz
>>>>> "Todd" == Todd Blanchard <[hidden email]> writes:

Todd> north := OrderedCollection new.
Todd> south := OrderedCollection new.
Todd> east := OrderedCollection new.
Todd> west := OrderedCollection new.
Todd> trick := OrderedCollection new.

It's been my observation that similarly named variables that are acted upon in
similar ways really ought to be part of a common data structure rather than
unrelated variables.

hands := IdentityDictionary newFrom:
  (#(north east south west trick) collect: [:each | each -> Set new]).

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Smalltalk is a Mystery to Me

tblanchard
And I'd guess you just totally blew the newbies input buffer with  
conceptual overload when he was just trying to get one thing working.

On Aug 22, 2008, at 10:10 PM, Randal L. Schwartz wrote:

>>>>>> "Todd" == Todd Blanchard <[hidden email]> writes:
>
> Todd> north := OrderedCollection new.
> Todd> south := OrderedCollection new.
> Todd> east := OrderedCollection new.
> Todd> west := OrderedCollection new.
> Todd> trick := OrderedCollection new.
>
> It's been my observation that similarly named variables that are  
> acted upon in
> similar ways really ought to be part of a common data structure  
> rather than
> unrelated variables.
>
> hands := IdentityDictionary newFrom:
>  (#(north east south west trick) collect: [:each | each -> Set new]).
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503  
> 777 0095
> <[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> See http://methodsandmessages.vox.com/ for Smalltalk and Seaside  
> discussion

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

Re: Smalltalk is a Mystery to Me

Randal L. Schwartz
>>>>> "Todd" == Todd Blanchard <[hidden email]> writes:

Todd> And I'd guess you just totally blew the newbies input buffer with
Todd> conceptual overload when he was just trying to get one thing working.

I'm of the belief that you don't show people bad style, no matter what their
level, and especially newbies, because they tend to fall back on what they
learn first.  Perhaps we differ in our experience, but I have plenty of
experience of this from my Perl course presentations.

At a minimum, you say "an experienced user would probably have put
these into a Collection, and you'll want to learn about those pretty
soon, as nearly every class uses a Collection of some kind."

Using separate variables in place of a collection often leads to mindless
cut-and-paste-and-slightly-edit code replication, and/or people asking "how do
I turn a string into a variable name".  Again, from experience.  These are not
behaviors you want to encourage in a newbie. :)

Admittedly, I should have done something less Smalltalk idiomatic:

hands := IdentityDictionary new.
hands at: #north put: Set new.
hands at: #east put: Set new.
hands at: #west put: Set new.
hands at: #south put: Set new.
hands at: #trick put: Set new.

Eventually, the newbie can learn that the cut-n-paste-and-slightly-edit that I
just did to make that can be replaced by a proper loop.  But at least that
cut/paste cycle won't be repeated everywhere else in the code.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[hidden email]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Smalltalk is a Mystery to Me

tblanchard

On Aug 23, 2008, at 4:44 AM, Randal L. Schwartz wrote:

> I'm of the belief that you don't show people bad style, no matter  
> what their
> level, and especially newbies, because they tend to fall back on  
> what they
> learn first.

My experience teaching for ten years at university is help beginners  
get something working fast (early success), then help them refine it  
as needed.  That's more like real development anyhow.  For instance,  
you represented each hand as a Set.  It won't be long before that  
turns out to be inadequate and they want a BridgePlayer to keep track  
not only of unplayed cards, but tricks they've won, their bid, etc...

Also I hinted at the value of collection when using the hands  
temporary to do the deal.  That was also intentional.

People improve over time and there is value in teaching them how to  
recognize when things need improvement (or refactoring as the  
buzzworders like to say).  It would not be long before the individual  
would recognize that he was doing too much boilerplate and start  
looking to reduce the work.

So there's my philosophy for teaching programming.  Stuff I post on  
newbies is often intentionally naive/simple/concept limited.

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

Re: Smalltalk is a Mystery to Me

Jerry Muelver-3
Randal has been right, more often than wrong, time after time since
about 1994, according to my Schwartz-tracking records. But this time,
I have to side with Todd. LEARNING how to do something is a different
operation entirely from KNOWING how to do something. Even allowing for
different "styles of learning", the best approach is helical rather
than straight-line: (a) Learn a new small piece, (b)integrate it with
what you already know, (c)use it, (d) go to (a). While it's good to
have an ultimate perfect goal, it is essential to have a productive
path to get to the goal.

---- Jerry Muelver

On 8/23/08, Todd Blanchard <[hidden email]> wrote:

>
> On Aug 23, 2008, at 4:44 AM, Randal L. Schwartz wrote:
>
>> I'm of the belief that you don't show people bad style, no matter
>> what their
>> level, and especially newbies, because they tend to fall back on
>> what they
>> learn first.
>
> My experience teaching for ten years at university is help beginners
> get something working fast (early success), then help them refine it
> as needed.  That's more like real development anyhow.  For instance,
> you represented each hand as a Set.  It won't be long before that
> turns out to be inadequate and they want a BridgePlayer to keep track
> not only of unplayed cards, but tricks they've won, their bid, etc...
>
> Also I hinted at the value of collection when using the hands
> temporary to do the deal.  That was also intentional.
>
> People improve over time and there is value in teaching them how to
> recognize when things need improvement (or refactoring as the
> buzzworders like to say).  It would not be long before the individual
> would recognize that he was doing too much boilerplate and start
> looking to reduce the work.
>
> So there's my philosophy for teaching programming.  Stuff I post on
> newbies is often intentionally naive/simple/concept limited.
>
> -Todd Blanchard
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>
>
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners