What is the (semantic?) difference (if any) between using:
if(something)
return true;
else
return false;
versus:
if(something)
return true;
return false;
Because (in this example situation) we’re using return as the only statement in each condition, I don’t see any difference between these two code bloks. But second one seems to be less readable for me.
Not necessary. I gave example with “if(something)” as… an example! :] Condition doesn’t always have to be boolean.
The same question goes for any kind of condition / check. What matters in my question, is that you always use return statement, which allows you to omit "else" part.
There’s no difference. But i agree, the first example is more clear. From a quick view you could miss the first return and thus think, that the function always returns false.
you can discuss which is more/less readable, but I would say something different:
for me it does not matter if you use ‘else’ or not, but you should always use curly brackets with if/for/do/while etc even if there is only one instruction. It is much more clear and prevent hard to trace errors when you add second instruction and forget to add brackets then
Using brackets makes both examples clear enough for me:
[color="#1C2837"][size=“2”]Not necessary. Because, as I wrote in an answer to alex-w, I just gave this example with “if(something)”. Condition doesn’t always have to be boolean. And if it is not, then your examples will fail.[/size][/color]
[color="#1C2837"][size="2"]But thank you for contribution.[/size][/color]