Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should a worker method generally be placed above or below the methods that call it? [closed]

Are there any conventions as to whether a method called by another method should generally be above or below it? E.g. say caller() was refactored into two methods - where would be the more standard place out of aboveCaller() or belowCaller()?

private void aboveCaller() { /*...here?...*/ }

public void caller() {
    aboveCaller();
    belowCaller();
}

private void belowCaller() { /*...or here?...*/ }

Although this is in Java, it is a general programming question and not really aimed at a specific language. (Apologies if it has been asked before - tried searching on here but didn't come up with anything).

like image 918
Steve Chambers Avatar asked Jan 07 '14 15:01

Steve Chambers


People also ask

What is the correct technique for lifting?

Where possible, hug the load as close as possible to your body. This may be better than gripping it tightly with just your hands. Slight bending of your back, hips and knees at the start of the lift is preferable to either fully flexing your back (stooping) or fully flexing your hips and knees (full/deep squatting).

What is the most effective method specifies in the hierarchy of risk control?

The most effective control measure involves eliminating the hazard and its associated risk. The best way to eliminate a hazard is to not introduce the hazard in the first place. For example, you can eliminate the risk of a fall from height by doing the work at ground level.

What do you call to the methods or procedures that are designed to minimize exposure to a hazard?

Administrative controls are work methods or procedures that are designed to minimise exposure to a hazard.

Which type of control measure should be considered last to protect workers?

Personal Protective Equipment This is the least effective, and least desirable, method of protecting workers, and is considered as the last line of defense against hazards. If the PPE is damaged or fails, the worker will be exposed to the hazard.


2 Answers

Following the top-down design, I first write the methods calls, then implement them, so they'll be under.

Others prefer them to be above the caller since it's clearer (You first encounter the implementation, then see the call).

One thing for sure, follow your convention.

like image 50
Maroun Avatar answered Sep 29 '22 07:09

Maroun


I don't think there is a convention. However, I usually put belowCaller below. It's a supporting function of the main function and I don't want to look at it until I come across it in the main function's content. That being said, I put all public functions first, followed by all private functions. I put class variables at the top. Also, javadoc for each non obvious function will help a lot in understanding the code.

like image 26
user2810910 Avatar answered Sep 29 '22 06:09

user2810910