Skip to content

Add more guidance on scope for constants #216

@tyler-french

Description

@tyler-french

Hoping to get some opinions on this.

One pattern I see a lot is with making global constants for values that are only used within a certain function.

For example

const _defaultPort = 8000

func something() {
  doSomething(_defaultPort)
  port := _defaultPort
}

In my opinion, there should be an adjustment to the # Reduce Scope of Variables section to include more emphasis on what to do with Constants.

I mostly want to get opinions here, but I generally would prefer to change the above code to the following:

func something() {
  const defaultPort = 8000
  doSomething(defaultPort)
  port := defaultPort
}

Thoughts?

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