Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: Methodical Dilemma
|
Posted: Mar 30, 2002 10:12 PM
|
|
As suggested above, returning an array of three ints does the trick.
It may be that returning an object is even better. For instance, if what you were returning is a point in 3-D space, then you'd want to return a Point3d (or more precisely, javax.vecmath.Point3d) object. This will be simpler to work with (you won't have to unpack the array into whatever form it really needs) and it will give you much more readible code. It will also help you to think more about your design and improve your object-oriented thinking. This will then contribute to you garnering the respect and admiration of your peers, which will, of course, inevitably lead to the formation of a fan club in your honor, an Oscar (don't forget to mention me in your acceptance speech), your very own star on Hollywood Boulevard, a Pulitzer and eventually a Nobel Prize.
Incidentally, one of cool features of the Python (http://www.python.org) programming language is that you can return more than one object or value, or at least appear to. You can do something like "return x, y, z" and it works fine. In reality, you are really only returning one thing, as the three things are wrapped into a tuple, but the effect is that it works like you have multiple return values, since you can also assign multiple variables when you call the method. So you might have something like this:
def Foo( x, y, z ):
# Do some incredibly interesting calculations.
return x, y, z
# Then, later use it like this:
a, b, c = Foo( d, e, f )
|
|