One seems to be that there should be no more than one return statement. For example, something like
Object result = null;
...
if (result == null) {
...
}
if (result == null) {
...
}
if (result == null) {
...
}
if (result == null) {
...
}
... and on and on ...
return result;
More often, though, it tends goes like
Object result = null;
try {
...
result = ...;
} catch (Exception e) {
...
}
return result;
There also seems to be a rule that a result variable has to be declared, so I see things like
Object result = ...;
return result;
where I would just write
return ...;
And then there's code from beginners that don't seem to realize that boolean expressions result in boolean values
boolean result;
if (...)
result = true;
else
result = false;
return result;
No comments:
Post a Comment