Waitaminnit.…

I’ve been try­ing to fig­ure out how to pass val­ues to meth­ods and return val­ues back to the caller in Java. Like in Perl I would do this:

sub gar
{
$in = $_[0];
$out = "gar gar gar $in gar gar gar";
return( $out );
}

and then every time I want to sur­round a string in gars I would just do some­thing like:

$newgarstring = gar( $stringtobegarred );
print "$newgarstring\n";

Now it’s occur­ring to me that maybe this is a part of my being stuck in bass-ack­wards pro­ce­dur­al think­ing. That just abstract­ing the method into a sub­rou­tine is a nice step toward mod­u­lar­i­ty, but that the point of being object-ori­ent­ed is not to be pass­ing things back and forth with a lin­ear in and out, but to ini­tial­ize a new object with the input and then access the result as a vari­able with­in that object.

Some­thing more like this:

public class Gar {
String garredString;
public static void main(String arg) {
garredString = "gar gar gar " + arg + " gar gar gar";
}
}

and don’t pass any­thing back, just cre­ate the new Gar object and grab the val­ue of Gar.garredString. Right?

or rather

g = new Gar("rag");
System.out.println(g.garredString);

…and the beau­ty to this method­ol­o­gy is that I don’t make new stuff in the com­mon name­space just to move stuff around, in and out and all that. I’m nev­er left with a messy return ($zik, $zak, $mikkle­wak, $rikkle­wak, .…ad nau­se­um… $even­more­wak); state­ment that returns every pos­si­ble thing I might want to know about the trans­for­ma­tion I just did; I can pick and choose after I instan­ti­ate a new object.

Is it pos­si­ble I’m start­ing to get it?

Dark Forces—Killing Joke

One Reply to “Waitaminnit.…”

Leave a Reply