swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Heatbug.java question


From: Benedikt Stefansson
Subject: Re: Heatbug.java question
Date: Thu, 13 Jan 2000 16:17:33 -0700

David Smith wrote:

> The confusing thing is that findExtremeType$X$Y() is used for something
> very different from its apparent purpose. Its return type is long. It
> returns the heat value of the optimum neighbor, but that value falls into
> the bit bucket because it is never used. I don't see where the function
> is used anywere else in jheatbugs either.

What you have stumbled upon is actually a good example of the difference 
between the object
oriented mindset and the traditional programming mindset.

Look at it this way. Neither C, Objective-C nor Java can return more than one 
value from a
function call. So to set x,y values simultaneously you must pass in the 
variables/objects to be
changed by the method and have the method set the values internally.

In the original Objective-C heatbugs, for better or for worse, there were no 
'coordinate'
objects used, so to set an (x,y) coordinate one passed two method variables by 
reference. In
the Java code the implementation is more OO oriented,  a coordinate object is 
passed and its
ivars are set by the callee.

The Java way is certainly cleaner and less errror prone, in fact I urge even 
those who wish to
stick to Objective-C coding to have a look at how the Java world does things. 
By that I mean
for example how everything is objectified, pointers are abandoned and things 
like global
parameters don't exist (pass around a parameter object instead).

Another thing. In this particular case the return value from 
findExtremeType$X$Y really has no
purpose, because the method does its job by setting values in the object that 
it is passed. One
purpose of the return value might be to flag whether a location was found and 
set or not, but
the code does not make use of it if I recall correctly.

Benedikt

--
Benedikt Stefansson      | address@hidden
CASA, Inc.               | Ph : (505) 988-8807 x101
Santa Fe, NM 87501       | Fax: (505) 988-3440




                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]