[erlang-questions] Use of application environment

Mazen Harake <>
Tue Nov 25 10:57:21 CET 2008


Resending...

/Mazen

Mazen Harake wrote:
> Personally I think in terms of isolation and how long the worker is 
> going to live.
>
> If the worker is short lived and doesn't depend on that the app env is 
> the same in several places... then I tend to use application:get_env.
> If the worker is a more heavy worker and depends on more rigid values 
> then I tend to copy the configuration to the state so that I can 
> control when a good time to update it is..
>
> Magically updating all the workers is not always a good thing... and 
> yes, applicationg:get_env is the same as using global variables.
>
> /Mazen
>
> Edwin Fine wrote:
>> Hi all,
>>
>> Is it considered bad practice to use application environment 
>> variables (i.e. application:get_env/2,3) in workers, as opposed to 
>> only passing config information via the start()/init() calls? I am 
>> finding it tedious as I add more configuration data to the sys.config 
>> file, to get_env() the data in a supervisor and then parcel it out to 
>> the workers. Also, it becomes a pain to change the values at runtime, 
>> whereas if I put a function like this in an affected worker
>>
>> my_foo_val() ->
>>     application:get_env(my_app, my_foo_val, ?SOME_SANE_DEFAULT).
>>
>> then runtime changes can be made immediately using set_env(), and it 
>> becomes much easier to add new config data, but I feel uneasy, almost 
>> as if I'm using global variables. From a load point of view, I only 
>> do this in places where the value is not used at a high rate.
>>
>> What is the preferred or recommended (or even most common) practice?
>>
>> Regards,
>> Edwin Fine
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>




More information about the erlang-questions mailing list