Effective handling of variables in non-object oriented programming

Posted by srnka on Programmers See other posts from Programmers or by srnka
Published on 2012-10-17T08:16:56Z Indexed on 2012/10/17 11:20 UTC
Read the original article Hit count: 264

Filed under:
|
|
|
|

What is the best method to use and share variables between functions in non object-oriented program languages?

Let's say that I use 10 parameters from DB, ID and 9 other values linked to it. I need to work with all 10 parameters in many functions. I can do it next ways:

1. call functions only with using ID and in every function get the other parameters from DB.

Advantage: local variables are clear visible, there is only one input parameter to function

Disadvantage: it's slow and there are the same rows for getting parameters in every function, which makes function longer and not so clear

2. call functions with all 10 parameters

Advantage: working with local variables, clear function code

Disadvantage: many input parameters, what is not nice

3. getting parameters as global variables once and using them everywhere

Advantage - clearer code, shorter functions, faster processing

Disadvantage - global variables - loosing control of them, possibility of unwanted overwriting (Especially when some functions should change their values)

Maybe there is some another way how to implement this and make program cleaner and more effective. Can you say which way is the best for solving this issue?

© Programmers or respective owner

Related posts about c

    Related posts about efficiency