[Tutor] Why None?

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Feb 7 21:37:32 CET 2006


Hi Chris,

I'm going to be a little insidous and bring some ideas from the textbook
"How to Design Programs."  (http://htdp.org)

Let's annotate each interesting method with what the method expects to
take in, and what it expects to return.

> 	def placeOrder(self, foodName, employee):


We can say that placeOrder takes in foodName and employee, and returns
None.  We can write this concept as a docstring, using a notation like
this:

##############################################
    def placeOrder(self, foodName, employee):
        """placeOrder: string Employee -> None
        ... [add description here]"""
        ## rest of body
##############################################

That is, we make it clear what the expected inputs and outputs are.


> 	def printFood(self):

printFood doesn't appear to take anything useful, and also doesn't return
anything useful.  Again:

################################
    def printFood(self):
        """printFood: -> None"""
        ## rest of body
################################

(Hint: this part is important.  Note that printFood() also returns None.)


If you do this slight annotation to the rest of the methods, it might make
it easier to see why Lunch.result() is giving slightly weird results.


Best of wishes!



More information about the Tutor mailing list