cmd/gofmt: proposal: place conditional single statement return on a single line (e.g. if err != nil { return err }
)
#60771
Labels
error-handling
Language & library change proposals that are about error handling.
FrozenDueToAge
Proposal
Four years ago, #33113 was opened and quickly closed. In the intervening time, there have been dozens of proposals to change the language with the common intent to reduce the amount of boilerplate code around error handling, almost all of which have been rejected. I suggest that this amount of effort put in by so many people trying to find an acceptable route toward similar goals represents a compelling reason to reconsider that closure, and possibly at least part of a compelling reason to accept this proposal.
This proposal makes tangible progress toward a goal shared by at least most of those other proposals, without requiring any change to the language or syntax. It will make long series of calls with simple error checkin easier to read, and by extension also improve the readability of the surrounding code.
The core of this proposal is to change the formatting of a block that contains a single return statement, to put the statement and
}
on the same line as the{
. Restricting this behavior to statements where one or all of the return values are present in the conditional for the block may be desirable. Restricting this behavior to statements where one or all of the return values were assigned in the statement prior to the conditional for the block may be desirable. Further specific examples and discussion of those details would likely be relevant to a design doc for this proposal.A significant potential negative impact of this change would be a large amount of code churn across projects using gofmt. This change would likely affect almost every source file containing functions, across all packages and projects.
The text was updated successfully, but these errors were encountered: