[CentralOH] Indicating Meaning of Items of Return Values
jep200404 at columbus.rr.com
jep200404 at columbus.rr.com
Sun Mar 11 23:37:17 CET 2012
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_?
More information about the CentralOH
mailing list