Skip to main content
Tweeted twitter.com/StackSoftEng/status/790284902575042560
deleted 6 characters in body
Source Link
Sandeep
  • 179
  • 1
  • 6

In general, I know that global variables are bad and their should be avoided. Are static global variables equally bad?

In all my projects, I have heavily relied on static global variables. From design perspective, how can I avoid using them.

Ex Use case :

Whenever the key is changed(by some other threads), my call back notifier is executed in which I update my static global variable with the new key. This key is used everywhere in the program to decrypt some data.

How can I avoid static globals in this case?

In general, I know that global variables are bad and their should be avoided. Are static global variables equally bad?

In all my projects, I have heavily relied on static global variables. From design perspective, how can I avoid using them.

Ex Use case :

Whenever the key is changed(by some other threads), my call back notifier is executed in which I update my static global variable with the new key. This key is used everywhere in the program to decrypt some data.

How can I avoid static globals in this case?

In general, I know that global variables are bad and should be avoided. Are static global variables equally bad?

In all my projects, I have heavily relied on static global variables. From design perspective, how can I avoid using them.

Ex Use case :

Whenever the key is changed(by some other threads), my call back notifier is executed in which I update my static global variable with the new key. This key is used everywhere in the program to decrypt some data.

How can I avoid static globals in this case?

Source Link
Sandeep
  • 179
  • 1
  • 6

Are static global variables as bad as global variables? How to avoid using them?

In general, I know that global variables are bad and their should be avoided. Are static global variables equally bad?

In all my projects, I have heavily relied on static global variables. From design perspective, how can I avoid using them.

Ex Use case :

Whenever the key is changed(by some other threads), my call back notifier is executed in which I update my static global variable with the new key. This key is used everywhere in the program to decrypt some data.

How can I avoid static globals in this case?