Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
1  
At the risk of seeming flip, PHP itself is frowned upon in OOP. If what you're doing works for you, go with it. –  Ross Patterson Feb 2 '13 at 3:06
add comment

1 Answer

up vote 2 down vote accepted

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.)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.