value - a trap for young players

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

value - a trap for young players

Jeff Gray
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...

Reply | Threaded
Open this post in threaded view
|

Re: value - a trap for young players

mmimica
On 12 June 2012 14:27, Jeff Gray <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: value - a trap for young players

Igor Stasenko
On 12 June 2012 14:48, Milan Mimica <[hidden email]> wrote:

> On 12 June 2012 14:27, Jeff Gray <[hidden email]> 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.

Reply | Threaded
Open this post in threaded view
|

Re: value - a trap for young players

mmimica
On 12 June 2012 14:55, Igor Stasenko <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: value - a trap for young players

Guillermo Polito

On Tue, Jun 12, 2012 at 5:52 PM, Milan Mimica <[hidden email]> wrote:
On 12 June 2012 14:55, Igor Stasenko <[hidden email]> 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

Reply | Threaded
Open this post in threaded view
|

Re: value - a trap for young players

Mariano Martinez Peck
In reply to this post by Jeff Gray


On Tue, Jun 12, 2012 at 2:27 PM, Jeff Gray <[hidden email]> 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

Reply | Threaded
Open this post in threaded view
|

Re: value - a trap for young players

Mariano Martinez Peck
btw, be careful that Object also understands #name :(


On Tue, Jun 12, 2012 at 8:57 PM, Mariano Martinez Peck <[hidden email]> wrote:


On Tue, Jun 12, 2012 at 2:27 PM, Jeff Gray <[hidden email]> 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

Reply | Threaded
Open this post in threaded view
|

Re: value - a trap for young players

Stéphane Ducasse


> btw, be careful that Object also understands #name :(

which one day we will kill.


Reply | Threaded
Open this post in threaded view
|

Re: value - a trap for young players

Guillermo Polito


On Tue, Jun 12, 2012 at 9:51 PM, Stéphane Ducasse <[hidden email]> wrote:


> btw, be careful that Object also understands #name :(

which one day we will kill.

soon
Reply | Threaded
Open this post in threaded view
|

Re: value - a trap for young players

Stéphane Ducasse
soon
Cooool :)
we are aligned and armed :)



Reply | Threaded
Open this post in threaded view
|

Re: value - a trap for young players

Jeff Gray
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 :-)
Reply | Threaded
Open this post in threaded view
|

Re: value - a trap for young players

Jeff Gray
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.