I've worked on multiple projects that were started by other people, and one thing I still don't really understand..
1) Sometimes I see a code-snippet like this:
public String retrieveSomething(){
String result;
result = doSomethingAndReturnTheResult();
return result;
}
2) Personally I've used to this instead:
public String retrieveSomething(){
return doSomethingAndReturnTheResult();
}
3) But from a fellow developer I've heard it's better to do this instead regarding debugging / breakpoints, which I think is indeed a fair point:
public String retrieveSomething(){
String result = doSomethingAndReturnTheResult();
return result;
}
I can understand the third option, but I see the first option pretty often from multiple developers and I just don't get it.. :S The only reason I could think of is alignment in the IDE where it's a difference between:
String result =
doSomethingAndReturnTheResult();
versus:
String result;
result = doSomethingAndReturnTheResult();
But apart from that I don't see the purpose. Does anyone else do as displayed in the first example, and if yes: why? Or do you have a plausible reason why developers might do this? Personally I think it only adds distractions and makes it less readable than the third example, but that could be just me..
I know this might be fairly opinion-based / lead to discussions, but you can basically translate the question to: What is the extra purpose of using example 1 over example 3 (if any)?
There also isn't really a suitable tag for this on SO.