I come from c++, where one declares all assets to be included at the top of a file. That is what I have been doing with php as well. Lately I have been tempted to stray from this rule: I have a script file where I put functions I use throughout my projects, sort of like a library script. There are some functions included that require assets that no other function uses, and since one can put require_once statements all throughout one's scripts, I have been tempted to include assets at the beginning of those functions, to conserve resources when the script is running. Is this kind of thing frowned upon in OOP, or is that OK? I guess while I am at it, should I not be doing this at all because there is a purerer OOP approach to the kind of library scripts I have been creating?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
The best answer is that you should follow the conventions / recommendation's set out in the language's style guides.
For instance, Sun's Java Style Guide recommends that you declare static variables, then instance variables, then constructors and then methods; see http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141855.html#1852.
(This order probably makes sense for other OO languages too ... if there are no commonly used style guides specific to the language.)