Timeline for Best practice on if/return
Current License: CC BY-SA 3.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 24, 2012 at 19:22 | comment | added | Chuck Conway | @tia I like the spirit of your code. Instead of the evaluating the userName twice I'd capture the first evaluation in a variable and return that. | |
Jul 20, 2012 at 10:56 | history | made wiki | Post Made Community Wiki by DPD | ||
Jul 20, 2012 at 10:07 | comment | added | tia | @Shadur We are not doing optimisation here, right? My point is to make my code easy to read and maintain, and personally I would pay that with the cost of one reference null check. | |
Jul 20, 2012 at 9:52 | comment | added | Shadur-don't-feed-the-AI |
You've STILL got the useless additional test. Return false inside the if statement, then return true outside of it. No need to run the second != test at all.
|
|
Jul 20, 2012 at 9:03 | history | edited | tia | CC BY-SA 3.0 |
added 164 characters in body
|
Jul 20, 2012 at 8:57 | comment | added | tia |
@Shadur I'm aware of extra boolean test and unused myString result. I just copy the function from OP. I'll change it to something that looks more real-life. Boolean test is trivial and should not be issue.
|
|
Jul 20, 2012 at 8:05 | comment | added | Shadur-don't-feed-the-AI | ... Frankly, I'm not sure why you even want the string in this case, not to mention why you're adding an extra boolean test at the end that you really don't need for any reason whatsoever. | |
Jul 20, 2012 at 7:48 | comment | added | Caleb | The question is why do you prefer that style? | |
Jul 20, 2012 at 6:34 | history | answered | tia | CC BY-SA 3.0 |