dimanche 5 mai 2019

Should I use a global variable in the function signature?

I'm writing some Go code and have a file with the program's general configuration variables. What's a good practice, to use them in the function's signature or just inside. Ie:

In signature:

func someFunction (maxRecords int) int{
  for i:=0; i < maxRecords; i++{
    ...
   }
}

Inside:

import global
func someFunction () int{
  for i:=0; i < global.maxRecords; i++{
    ...
   }
}

At first started with the first option but found I never had to use different values for different functions that use some global variables (well, that's what global variables are for) and then refactored to the second option but I wonder what's the best practice on this regard no matter the language.

Thanks!

Aucun commentaire:

Enregistrer un commentaire