Passing arguments and speed

Hi forum,
I’ve been passing arguments all over the place to make my code more object oriented and logical, which I assume is what everyone does.
Let’s take a fictional scenario where I can better illustrate my question:
I have a “Main.java”, which extends SimpleApplication and has access to an instance of ViewPort called viewPort (just as it has access to assetManager and the rest). Say I also have a class called “Scene” which is supposed to represent everything Scene-related. Now, to set the viewPort’s background color, I could pass viewPort to Scene in the constructor like so:

ViewPort viewPort;
public Scene (ViewPort viewPort) {
this.viewPort = viewPort;
viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
}

Or I could just call

viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));

In my SimpleApplication, which would make the code less object-oriented, but is it having any kind of effect on the overall speed of my program by passing all these variables around between classes? I doubt I would ever change from this way of programming, but I am just wondering how much speed could be gained by being procedural.
Oh, and the “Howdy, glcheetham” at the top of the new forums is a nice touch, howdy to you too :slight_smile:
Thanks,
glcheetham

Don’t moan at me for not using code tags, new forum new layout I guess, I can use tags but apparently it does nothing

Nothing, its really just passinga pointer around in the internals, and you have a pointer to the object anyway.

Huh? It does do something!

public static main(String[] args) {
System.out.println(“This is wrapped in a code element”);
}

Thanks Phoenix,

How on earth do you use these code tags? 

I actually go exaclty the opposite way. I have many components aka AppStates and get the needed variables from a component which has access to it. As long as you always have access to the central component manager you have access to everywhere.

Even if i write more when getting a variable, i save a lot of time since i never have to modify the constructor/call. And since my main component handler finds all components in the classpath i don’t even have to initialize them :wink:

But there are better software architects here then me, so all above is just my way of dooing it

Add: My version is probably not as fast since it requires a lot of lookups, but once finised and i am not happy with the performance i can always microoptimitate (Getting all needed variables once at startup)

Thanks Phoenix,
1. How on earth do you use these code tags?

whaaaat? @normen how did you make that quote? I can only quote myself
Thats probalby because you own the key :wink:

Add: acutally i can quote myself, and the first post in a topic

Passing arguments Vs global variable is an old question. From an “object” point of view, global variable (not to mention static variables…) are hell on earth.
However, passing arguments all along do require lots of pushing on the stack and handling. So that’s not free either…

Personally, I tend to pass the maximum of things as variables, except in two cases :

  1. time-critical parts
  2. recursive calls where stack may overflow. Here any local variable counts and must be avoided if possible. Even if it means computing more… Spending more time is still better that no result at all!

But of course, this is only my point of view…

2) recursive calls where stack may overflow. Here any local variable counts and must be avoided if possible. Even if it means computing more…. Spending more time is still better that no result at all!

Depends, normally you know the maximum depth (else the requirements of the method are kinda incomplete) so its easily possible to adjust the used method to that value.