Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Confusing code #17

@pwaller

Description

@pwaller

This is only a minor suggestion, but I found this confusing:

perf/record_test.go

Lines 219 to 225 in 239c48f

const errDisabledTestEnv = "PERF_TEST_ERR_DISABLED"
func init() {
// In child process of testErrDisabledProcessExist.
if os.Getenv(errDisabledTestEnv) != "1" {
return
}

  1. Variables/consts beginning with the name err are usually errors.

  2. It refers to testErrDisabledProcessExist which doesn't exist.

  3. It's unclear from the comment which side of the branch is "in" something. Is it in the returning side, or the non-returning side? This might be a rare case where "early return" is a minor hinderance and perhaps it would be better to phrase it positively, and move the body of code out, to make it clear when the special condition matches:

    func init() {
      if specialCondition {
        doSpecialCondition()
      }
    }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions