starsimhub / styleguide

Guidelines for contributing to Covasim and other "starsim" models
MIT License
0 stars 0 forks source link

Do not require all functions to explicitly call Return #8

Open daniel-klein opened 10 months ago

daniel-klein commented 10 months ago

The style guide recommends that all functions end with an empty Return statement. This statement has the effect of returning None from the function. However, the same functionality can be achieved without the return statement because None is returned automatically when the end of a function is reached.

Personally, I find it annoying to have (inconsistent) Return statements sprinkled throughout the code. I find they confuse more than add to readability.

In chatting with @cliffckerr, one consideration of recommending that all functions end with a return is that it forces developers to consider if None is really the best return value. TBH, I'm not convinced this specific recommendation in the style guide has the intended consequences.

My recommendation is to change the style guide to recommend against concluding every function with a return statement.

cliffckerr commented 5 months ago

I am still in favor of explicit returns, but we can revisit at a later date. PEP8 and the Google Style Guide don't cover this point, other than to recommend using an explicit return None if non-None return values are also possible from a function. RealPython suggests that omitting return can be confusing for users coming from other languages. I agree that it doesn't make much difference which convention we choose, so long as we are consistent about it!