Re: small java exercise
On Apr 3, 5:46 pm, Patricia Shanahan <p...@acm.org> wrote:
bcr666 wrote:
On Apr 3, 5:37 am, "vishist" <vishi...@gmail.com> wrote:
public boolean getStatus(String rating, int age){
Integer ratingAge = (Integer)humanMap.get(rating);
if(ratingAge != null)
{
int minAge = ratingAge.intValue();
if (age < minAge ){
return false;
}
else{
return true;
}
}
return false;
}
I am a big believer in one exit point for a method, so I would do the
following
Why one exit point per method?
[I used to believe that, but most of the logical reasons I can
articulate are covered by try-finally. I'm curious about whether there
is a better reason I'm missing.]
Patricia
Having come from a procedural language background, I was always taught
5 rules that could not be broken:
1) Single Entry Point
2) Single Exit Point
3) No GOTO's allowed
4) No self-modifying code.
5) One procedure, one function
Having been trying to learn Java, I am now of the opinion that one can
still write well structured programs yet not be regimented by the
above rules, more over numbers 1 and 2.
I found this site http://ivan.truemesh.com/archives/000611.html
which appears to agree with me. And just to quote a section of the
above site,
Longer functions that use the "single exit
point" rule can get really convoluted and difficult
to understand. Having a function return as
soon as it can improves the clarity because it
improves the "locality" of the code.