Skip to content

Single exit point #5

@jbgi

Description

@jbgi

(this is duplicated from gitbook discussion, because not sure where most people watch the project)

I like most of the guidelines of the book, however I find the judgment on "Single exit point" style overly harsh.

Single exit point is effectively mandated in most (all?) functional languages. Are you sure that Haskell "works at a lower level than Java"?

The "Single exit point" example is said "Overly complex", I don't really agree, but anyway the example is not fair. A good single return point style would be one of the method of gist.github.com/jbgi/c60acbfd7870237d0de6

The advantages of single return point associated with a final result variable (or no result variable) are two fold:

  1. you ensure proper case analysis. (you can easily forget one "return" in the case of multiple return style and then it silently slip through, like when you forget a break in a switch)
  2. you can easily extract part of the method into another: you cannot do that if the part of the method you want to extract contains a return: a single return point method can easily scale when more cases are added, a multiple return method cannot.

Can the overly harsh judgment be corrected ? or the section be removed all together ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions