I ask myself this question every time I'm coding, because I always worry about leaving my code understandable to other programmers who will be looking at it - and myself, because maybe I will not remember what I did there.
Would it be a good idea to omit else
on some occasions, as in this case?
$usuario = Usuario::find($id);
if (is_null($usuario)) {
return Response::json(['error' => 'Usuário não encontrado');
}
return Response::json(['error' => false, 'usuario' => $usuario]);
Or, for some readability, should I do so?
$usuario = Usuario::find($id);
if (is_null($usuario)) {
return Response::json(['error' => 'Usuário não encontrado');
} else {
return Response::json(['error' => false, 'usuario' => $usuario]);
}
How could it be harmful to (or not) the else
(in cases such as these to facilitate)?