Monday, March 4, 2024

Global Inheritance

The main reason for a adopt a object kind of style in procedural programing is because procedural or raw programing style is to complex. We can see that functions, the base of prog is to hard to manage.


 This is done by separete "settings from logic" in the functions.


A example of a nested function that recive 3 variables: 


Function test_vars(var1, var2, var3)

{

int result;

result = var1 + var2 + var3;

printf(result)

}


These aproach have 2 main problems. One is scoop of variables and the other is the nesting of variables. 

Enviorment or scoop for the variables demands thats calls  to be used in conjuntion width function "test_var" its assume the same scoop or enviorment.

which is often local, need to have them keep close or in the same file due to this connection.

Example of a file:

int var1 = 11

int var2 = 4

int var3 = 3

test_vars(var1, var2, var3)


The secound problem :

the test_vars()  once changed need to be changed in 40 files. Like if we need to pass 4 variables or no longer need to pass a 3ยบ variable. The problem is that now we already callned this function in this format in several files. Is to static to work width.


Solution :

Make variables global to not need to change our functions we just need to chage 2 file and is where the function includes are.

Our new variables which represent prototype file and the function file where our test_vars() is, width the new functionality on the function.


The "includes" folder should have a global_variables.h file width all our global variables.

This stuff grows by adding more prototypes. So your global_variables file have all this prototypes for call kind of actions.


the new enviorment looks like :

  • 40 files calling the functions test_vars()
  • 1 file width the global variables.
  • 1 file width the global function.
  • test_vars() no longer is nested we can do width it all we want to.


Our new format transformas the function in to more a link for funcionality then a funcionality it self. Which is often is better. The more static you build harder it is to change which leads to more work needed.

No comments:

Post a Comment

hi

Rules

Rules, Steps & methods This is the current way to implement and be implemented but there could be more things to add : Root or loader  (...