3 ms·
But for example your indent if(someCrap != null) { followed by indentation on the following block, would be turned by the programmer into something like: if(
by logicallee 10y ago
But for example your indent
if(someCrap != null) {
followed by indentation on the following block, would be turned by the programmer into something like:
if(someCrap == null) return; //nothing to do
without an indent following.
thereby saving the indent and having to have the reader keep track of another level.
How many times have you seen:
}
}
}
}
And is it really that great?
Breaking it into line by line is actually easier to follow than nested conditions. (You don't have to worry about proper indentation or matching braces properly, it's simply easier to write.)
I think it's easier to read as well.
- dheera 10y agoI agree with you if that's all it were. But sometimes it's if(someCrap == null) { try { CrapSurface mCrapSurface = CrapGenerator.generateSomeCrap(CrapGenerator.CRAPPY, new CrapFactory.CrapOptions(new CrapOptionsCallBack() { @Override int getHeight() { return 5; } @Override int getWidth() { return 9; } })); someCrap = CrapSurface.getCrap(); } catch (SomeException e) { try { someOtherFailSafeButInefficientWayToGenerateTheCrap(); } catch (WeirdExceptionThatWillSeriouslyNeverHappenButStupidJavaRequiresMeToHaveATryCatchClauseAnyway f) { // do nothing because this exception will never happen and if it happens the user deserves it } } } else { ... the other code I had before ... }
- rootlocus 10y agoif(someCrap == null) { someCrap = makeNewCrap(); } That's more readable and less indented. It's also self documenting. } catch (WeirdExceptionThatWillSeriouslyNeverHappenButStupidJavaRequiresMeToHaveATryCatchClauseAnyway f) { // do nothing because this exception will never happen and if it happens the user deserves it } Nice joke, don't do this. I don't believe it's the user's fault, and even so either print the stack trace or name the exception `ignored`. It's not that hard to pipe all ignored exceptions in a single catch. Also, somebody made the conscious decision of making that exception checked, which means it's the implementor's fault for forcing you to catch it. If you want, you can use lombok's `@SneakyThrows`.
- hehheh 10y ago> That's more readable and less indented. It's also self documenting. It also pushes you ever closer to the dex method cap imposed by Android, unfortunately.
- imtringued 10y agoI just do this when I don't want to handle a checked exception. throw new RuntimeException(e);
- logicallee 10y agothis is hilarious :) thanks.