[[ blog 이사 과정에서 정확한 posting날짜가 분실됨. 년도와 분기 정도는 맞지 않을까? ]]

There is several important reason trying to avoid using global variable. One of them is "Tracking usage is very difficult.". It is extremely difficult for developer to know enough when this variable is used and changed.
It is also true for static variable in C and member variable in C++, JAVA and so on. Let's focus on the case of static variable in C (the case of member variable is also same.).
In simple and short file (ex. less than 500 lines), it's not matter. But, static variable in large-size-file is also difficult to track. Yes, we should keep file small. But in practice, this case is not rare. Whenever we use static variable in large-size-file, we should take care of it. Especially, using flag and state is top of that. In many cases, flag and state are used to branch. So, tracking these values are very important. Let's see following example.

static int _b_ui_mode = FALSE;
static int _operational_mode = IDLE;
funcA ()
{
  ...
  _b_ui_mode = TRUE;
  _operational_mode = USER_INPUT;
}
...
funcP()
{
  if(_operational_mode == IDLE){
    ...
  }
}
...

This is bad example. Assigning value to the static variable directly - especially to the flag and state variable - is the main reason to make tracking software difficlut. At least we should use get()/set() function.; Even in worst case, this makes logging easy. This is minimal requirement to use static variable in large-size-file.

+ Recent posts