Waitaminnit.…
I’ve been trying to figure out how to pass values to methods and return values back to the caller in Java.
sub gar
{
$in = $_[0];
$out = "gar gar gar $in gar gar gar";
return( $out );
}
and then every time I want to surround a string in gars I would just do something like:
$newgarstring = gar( $stringtobegarred );
print "$newgarstring\n";
Now it’s occurring to me that maybe this is a part of my being stuck in bass-ackwards procedural thinking. That just abstracting the method into a subroutine is a nice step toward modularity, but that the point of being object-oriented is not to be passing things back and forth with a linear in and out, but to initialize a new object with the input and then access the result as a variable within that object.
Something 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 anything back, just create the new Gar object and grab the value of Gar.garredString. Right?
or rather
g = new Gar("rag");
System.out.println(g.garredString);
…and the beauty to this methodology is that I don’t make new stuff in the common namespace just to move stuff around, in and out and all that. I’m never left with a messy return ($zik, $zak, $mikklewak, $rikklewak, .…ad nauseum… $evenmorewak); statement that returns every possible thing I might want to know about the transformation I just did; I can pick and choose after I instantiate a new object.
Is it possible I’m starting to get it?
By Jove Scotten, you’ve got
By Jove Scotten, you’ve got it!!