value - a trap for young players
So, for fun I wrote a PlayingCard class with two instance variables, suit and value. calling collect: [:eachCard | eachCard value] on a collection of cards didn't work as I'd expected, but of course 'value' is the method on Object that returns self. Easily fixed by renaming the 'value' variable to faceValue (and associated accessors), but made me laugh... -- View this message in context: http://forum.world.st/value-a-trap-for-young-players-tp4634470.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
On 12 June 2012 14:27, Jeff Gray <jeff@rogerthedog.com> wrote:
So, for fun I wrote a PlayingCard class with two instance variables, suit and value. calling collect: [:eachCard | eachCard value] on a collection of cards didn't work as I'd expected, but of course 'value' is the method on Object that returns self.
Easily fixed by renaming the 'value' variable to faceValue (and associated accessors), but made me laugh...
PlayingCard>>value will override Object>>value. Noting funny about that. -- Milan Mimica http://sparklet.sf.net
On 12 June 2012 14:48, Milan Mimica <milan.mimica@gmail.com> wrote:
On 12 June 2012 14:27, Jeff Gray <jeff@rogerthedog.com> wrote:
So, for fun I wrote a PlayingCard class with two instance variables, suit and value. calling collect: [:eachCard | eachCard value] on a collection of cards didn't work as I'd expected, but of course 'value' is the method on Object that returns self.
Easily fixed by renaming the 'value' variable to faceValue (and associated accessors), but made me laugh...
 PlayingCard>>value will override Object>>value. Noting funny about that.
why not? i use value for own purposes.. of course, if it fits and if there's no other more appropriate name for an object's property
-- Milan Mimica http://sparklet.sf.net
-- Best regards, Igor Stasenko.
On 12 June 2012 14:55, Igor Stasenko <siguctua@gmail.com> wrote:
PlayingCard>>value will override Object>>value. Noting funny about that.
why not? i use value for own purposes.. of course, if it fits and if there's no other more appropriate name for an object's property
Me too. Still, nothing funny. But ok, people laugh at different things. -- Milan Mimica http://sparklet.sf.net
On Tue, Jun 12, 2012 at 5:52 PM, Milan Mimica <milan.mimica@gmail.com>wrote:
On 12 June 2012 14:55, Igor Stasenko <siguctua@gmail.com> wrote:
PlayingCard>>value will override Object>>value. Noting funny about
that.
why not? i use value for own purposes.. of course, if it fits and if there's no other more appropriate name for an object's property
Me too. Still, nothing funny. But ok, people laugh at different things.
Don't be hard :). He probably was expecting the code to fail, found it wasn't, and he understood why. Learning is fun :)
-- Milan Mimica http://sparklet.sf.net
On Tue, Jun 12, 2012 at 2:27 PM, Jeff Gray <jeff@rogerthedog.com> wrote:
So, for fun I wrote a PlayingCard class with two instance variables, suit and value. calling collect: [:eachCard | eachCard value]
off topic but also fun is that you can do: collect: [:eachCard | eachCard faceValue ] then you can do: collect: #faceValue. but I don't like that..it feels hackish to me. funny, what if you do collect: #value ? hahahaha
on a collection of cards didn't work as I'd expected, but of course 'value' is the method on Object that returns self.
Easily fixed by renaming the 'value' variable to faceValue (and associated accessors), but made me laugh...
-- View this message in context: http://forum.world.st/value-a-trap-for-young-players-tp4634470.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
-- Mariano http://marianopeck.wordpress.com
btw, be careful that Object also understands #name :( On Tue, Jun 12, 2012 at 8:57 PM, Mariano Martinez Peck < marianopeck@gmail.com> wrote:
On Tue, Jun 12, 2012 at 2:27 PM, Jeff Gray <jeff@rogerthedog.com> wrote:
So, for fun I wrote a PlayingCard class with two instance variables, suit and value. calling collect: [:eachCard | eachCard value]
off topic but also fun is that you can do:
collect: [:eachCard | eachCard faceValue ]
then you can do:
collect: #faceValue.
but I don't like that..it feels hackish to me.
funny, what if you do collect: #value ? hahahaha
on a collection of cards didn't work as I'd expected, but of course 'value' is the method on Object that returns self.
Easily fixed by renaming the 'value' variable to faceValue (and associated accessors), but made me laugh...
-- View this message in context: http://forum.world.st/value-a-trap-for-young-players-tp4634470.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
-- Mariano http://marianopeck.wordpress.com
-- Mariano http://marianopeck.wordpress.com
The missing part of my story was that being lazy I had not written the value accessor method, so calling calling it in the collect as giving me a collection of cards rather than a collection of the cards' values. Yes - beginner learning is fun :-) -- View this message in context: http://forum.world.st/value-a-trap-for-young-players-tp4634470p4634552.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Funny - Mariano's comments made me rethink (don't want to do anything hackish :-)) and moving some logic to perhaps a more appropriate class has given me a more elegant solution. The problem I'm solving is to look at a collection of 7 cards (Texas Holdem: 2 cards per player and 5 community cards) and make the best 5 card poker hand, that can be compared to others. It's a good exercise. -- View this message in context: http://forum.world.st/value-a-trap-for-young-players-tp4634470p4634563.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
participants (6)
-
Guillermo Polito -
Igor Stasenko -
Jeff Gray -
Mariano Martinez Peck -
Milan Mimica -
Stéphane Ducasse