Skip to content

Early return from a function is not always a good idea. #95

Description

@baynes

"always return a function's value as early as possible"

I think you should put some caveats on this. Returns (and breaks and other break out statements) buried inside blocks of code are easily missed and are a very significant source of bugs on later modifications to the code (I speak with many years of experience).

For me returns should either be in the first few lines of the function (where some simple ifs deal with trivial cases) or in the last few lines of a function.

If one has to put a return in the middle of a longer function then I would make it stand out with a comment so it is not easily overlooked.

    return;   // ****************** RETURN *********************

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions