Skip to content

Rethink the usage of global variables #32

@adutra

Description

@adutra

We have a few global variables, e.g.:

  • message.DefaultMessageCodecs
  • client.HandshakeHandler
  • and all the datatypes and data codecs in datatype package.

Global variables are not guaranteed to be immutable, and even if they are (because the type is an interface with only accessor methods), one could still set the variable to nil.

For example you cannot forbid a user from doing:

message.DefaultMessageCodecs = nil
datatype.Int = datatype.Varchar

... which would screw up the library.

The Go community itself seems to hesitate about using global variables. Several packages have global variables, e.g. time.UTC.

We need to asses if it's safe to keep the global variables around or if we should remove them.

Relevant articles on this topic:

Metadata

Metadata

Assignees

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