<<< Descriptive Names     Index     Maintainability >>>

6. Keeping Scopes Small


  • Data abstraction and hiding closely relates to the scopes of variables and operations.

  • In view of good design we must pursue the goal of localizing attributes and behaviors as much as possible.

  • This greatly improves debugging, testing, documentation, and extensibility of the entire system.

  • Keeping minimal scopes emphasizes good programming style.

  • Consider:

    
        int temp;
        void swap( int* pleft, int* pright )
        {
            temp = *pleft;
            *pleft = *pright;
            *pright = temp;
        }
    
    
  • Better:

    
        void swap( int* pleft, int* pright )
        {
            int temp = *pleft;
            *pleft = *pright;
            *pright = temp;
        }
    
    
<<< Descriptive Names     Index     Maintainability >>>