nakedreturn

package
v0.0.0-...-0c3c093 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package nakedreturn defines an analysis pass that checks that there are no naked returns.

A naked return is a return statement that does not explicitly specify the names of the variables being returned and instead rely on named return values for that purpose.

Naked returns increase cognitive load by requiring the reader to remember the names of the return values while they are reading a function.

With explicit returns, the reader can start reading at any given return statement and step backwards through the function definition. Since reversing through a function definition normally doesn't include branches, this strategy for code comprehension is often simpler. Reading functions in reverse sometimes allows the reader to stop once they have collected enough context.

Sometimes, for very short functions, naked returns can be quite elegant. However, it is my belief that they are mostly abused and not worth it.

Being explicit is usually better.

Index

Constants

View Source
const Doc = `` /* 200-byte string literal not displayed */

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:             "nakedreturn",
	Doc:              Doc,
	Requires:         []*analysis.Analyzer{inspect.Analyzer},
	Run:              run,
	RunDespiteErrors: true,
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL