My colleague showed me this piece of code, and we both wondered why there seemed like too much code:
if (response.status().code() != Status.OK.code() || !response.payload().isPresent()) {
if (response.status().code() != Status.NOT_FOUND.code() || !response.payload().isPresent()) {
LOG.error("Cannot fetch recently played, got status code {}", response.status());
}
return Lists.newArrayList();
}
// ... (more code)
I thought this might be a simpler representation:
if (S != 200 || !P) {
if (S != 404 || !P) {
Log();
}
return;
}
// ...
Is there a simpler way to write this, without duplicating the !P? If not, is there some unique property about the situation or conditions that makes it impossible to factor out the !P?
Aucun commentaire:
Enregistrer un commentaire