Unused variables

  • Unused variables in blocked scope are not allowed in Go since they cause maintenance nightmares. If we declare a variable in blocked scope then we must use it or else completely remove it from the block. We cannot have unused variables declared in blocked scope dangling in our source codes. Go throws unused variable errors at compile time only.
  • We should avoid using package level variables. Go doesn’t throw unused variable errors at compile time for variables declared at package level.

See also