pythoncode-standards

Coding standards: Should one always write 'return' at the end of every method or function?


I believe that the question is not a duplicate as the other question does not respond to the question of readability.

In the contributing guidelines of the library scikit-learn, they refer to a document for coding standards, see here, in which you can find the following remarks:

        # Functions/methods that do not return a value should still be
        # delimited by a return statement.  Please tell me you don't have to
        # ask why!
        return

However, there is no difference in the return value, and I don't see the improvements in readability of the code. I looked for people that detailed this point, but none of them tackled this subject from the angle of readability.

So why is it better to write return everytime ?


Solution

  • In this example they refer to the return statement as a delimiter, hence a visual way to identify the end of a function block.

    This is not an official part of PEP and personally I don't think it is necessary as Python has strong enough visual cues with indentation.