[CentralOH] Indicating Meaning of Items of Return Values

Mark E Erbaugh mark at microenh.com
Sun Mar 11 23:44:10 CET 2012


On Mar 11, 2012, at 6:37 PM, jep200404 at columbus.rr.com wrote:

> How do you indicate _meaning_? 
> 
> When returning multiple things such as in a tuple or list 
> from a function or method, what are good ways of referring to the 
> individual items that convey _meaning? 
> 
> For example, the indexes of bar leave no clue as to what 
> its items mean in the following code. 
> 
>    def foo():
>        ...
>        return search, holy, grail
> 
>    def main():
>        bar = foo()
> 
>        # The indexes of bar give no clue as to meaning. 
>        snafu = bar[0] * bar[1] + bar[2]
> 
> I am playing with the following to indicate meaning. 
> 
>    #  Indexes for return values are: 
>    (SEARCH, HOLY, GRAIL) = range(3)
>    def foo():
>        ...
>        return search, holy, grail
> 
>    def main():
>        bar = foo()
> 
>        snafu = bar[SEARCH] * bar[HOLY] + bar[GRAIL]
> 
> What are better ways of conveying meaning? 
> The normal way of returning things is with a tuple, 
> of which the items are accessed by numerical index. 
> Should I return a dictionary as follows? 
> That seems too much. 
> 
>    def foo():
>        ...
>        return {"SEARCH": search, "HOLY": holy, "GRAIL": grail}
> 
>    def main():
>        bar = foo()
> 
>        snafu = bar{"SEARCH"} * bar{"HOLY"} + bar{"GRAIL"}
> 
> How do you indicate _meaning_? 


How about:

search,holy,grail = foo()

?




More information about the CentralOH mailing list