[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

What's the difference?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 7
Thread images: 1

File: else.png (5KB, 368x248px) Image search: [Google]
else.png
5KB, 368x248px
What's the difference?
>>
There is no functional difference.

thank you, never stop believing
>>
It's a matter of aesthetics..
Which you're going to choose largely depends on the sizes of code1, code2 and code3.
>>
>>338435
Functionally, there's no difference.

Stylistically, some would argue that including the else makes it clear that the programmer thought of what should happen in that situation. And some would argue that's a dumb rationale and people would catch it in code review if it was really a problem. Of course I have absolutely no opinion on this at all. ;)
>>
>>338545
Personally, I'm inclined to prefer the former as a matter of style. If all branches of the if lead to a return, but the programmer still provides an else anyway, it might lead me to believe they think there's a chance it could fall through. making it "clear that the programmer thought of what should happen in that situation" doesn't really make sense to me here as a style argument, since if they write more code under it... that's what they intend to happen in that situation
>>
>>338560
>since if they write more code under it... that's what they intend to happen in that situation
Yeah, but how do you know they specifically decided the "else" block is unnecessary. As opposed to forgetting it.

I can't say I outright hate this reasoning, but it's problematic because it's targeted towards coders who aren't thorough. The ones who can't/won't independently test their own stuff before a formal review. Otherwise they will almost certainly spot an issue like this and correct it.
>>
>>338581
Sorry, I fail to see how this is "targeted towards coders who aren't thorough". Maybe I'm misunderstanding you. Is one less likely to test their code for writing it like this?

I see what you mean about the possibility of forgetting the else, but to me this is just dual to the problem I mentioned.
- Did they leave out the else? Maybe they forgot to write it.
- Did they include an else, when I just read an if block whose every branch exits the function? Maybe they forgot to write the case that would fall below this else.

In this light, I'm pretty sure whatever you're saying about thoroughness applies to both cases equally.

I think I'm liable to say at this point that neither presents a clear advantage over the other, which is why it isn't important which you choose

namaste
Thread posts: 7
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.