coding style: use if/elif/else if each branch returns? -
Which coding style do you prefer, and why?
If case1: return res1 if Case2: return res2 returns res3
or:
if case1: return res1 Elif case2: return res2 else: return res3
or:
res = none if case1: res = res1 elif case2: res = res2 and: Res = res3 Return
Reason: I have a code that looks like this, and I'm wondering what is the obvious way to express it. Personally, I can not decide between 1 and 2, and I will not consider the third thing.
I was about to make this language unknown, but I realized that in functional languages this is not the issue, as it is in the case of default 2 = p.
If each of them is a complete function, then it probably does not matter. For more complex tasks, I like the third because the code can not be easy to read after a few months.
On a similar note, if I want to take something like the third answer for some post processing, then they can remember it to avoid the first time. There are happy fun debugging times that the conditions are not mutually exclusive.
Comments
Post a Comment