Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 18th, 2005, 11:46 AM
Thomas Philips
Guest
 
Posts: n/a
Default Passing objects to a function

I'd like to write the parameter list of a method or function in a way
that makes the class of each parameter crystal clear, thus decreasing
the likelihood of a programming error.

I am programming a blackjack game with Card and Hand objects, and
these in turn have methods that require Card objects, Hand objects or
both. For example, the class Hand has a method BlackJackValue that
computes the value of a hand using the rules of blackjack. I'd like to
write the method (approximately) in the form

def BlackJackValue(hand=Hand):
adfsadf
adfasdf



  #2  
Old July 18th, 2005, 11:46 AM
John Roth
Guest
 
Posts: n/a
Default Re: Passing objects to a function


"Thomas Philips" <tkpmep@hotmail.com> wrote in message
news:b4a8ffb6.0405091315.5ecadf92@posting.google.c om...[color=blue]
> I'd like to write the parameter list of a method or function in a way
> that makes the class of each parameter crystal clear, thus decreasing
> the likelihood of a programming error.
>
> I am programming a blackjack game with Card and Hand objects, and
> these in turn have methods that require Card objects, Hand objects or
> both. For example, the class Hand has a method BlackJackValue that
> computes the value of a hand using the rules of blackjack. I'd like to
> write the method (approximately) in the form
>
> def BlackJackValue(hand=Hand):
> adfsadf
> adfasdf
> .
> .
> .
>
> It takes only one look at this method's definition to realize that it
> requires an object of type Hand. Unfortunately, my mangled syntax
> describes the way in which default parameters are passed, and does not
> allow me to document the class of each parameter. What's the right way
> to achieve my goal?
>
> Sincerely
>
> Thomas Philips[/color]

Since Python is not a language that supports manifest typing
(that is, type declarations) there is no "right" way to do what
you want. When I want to do something like that, I may go
Smalltalkish and say something like:

def BlackJackValue(aHand):

or I may go a bit more conventional and say something more
like:

def BlackJackValueOfHand(theHand):

In either case, you can always write a parameter name so that
it tells you something. Beyond that, it's simply a matter of setting
a convention and sticking to it rigorously.

John Roth


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.