## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

# Namespaces

Namespaces allow us to use the same name for different functions or variables in different contexts without causing ambiguity. For example, consider two material models: metal and rubber. Both may have a function named `execute`. Without namespaces, defining these functions with the same name in a global scope would lead to a naming conflict. By placing `execute` within respective namespaces, we can easily tell them apart.

Namespaces are a powerful tool that enables us to define multiple functions or variables with the same name without causing ambiguity. This is particularly useful when working with different material models, such as metal and rubber, which may share common functionality but require distinct implementations.

For instance, consider two material models: `mat_metal` and `mat_rubber`, each of which might have a function named `execute`. Without namespaces, defining these functions in the global scope would result in a naming conflict, and compilation errors.

By placing the `execute` function within its respective namespace, we can easily differentiate between the two implementations. This not only improves code organization and maintainability but also reduces the likelihood of bugs and errors.

    namespace user_metal
    {
        void execute()
        {
        }
    } // namespace user_metal

    namespace user_rubber
    {
        void execute()
        {
        }
    } // namespace user_rubber

    int function()
    {
        // Call metal execution
        user_metal::execute();

        // Call rubber execution
        user_rubber::execute();
    }