Namespaces And Simplicity

Hello all,

I have a question about namespaces… The PHP manual says the following:

Yii2 currently uses "sub-namespaces", meaning something like:


namespace yii\helpers\base;

In my opinion, this doesn’t alleviate the Extra_Long_Names problem. It might even make things more complex. (“Which namespace do I need to include??”)

What about we have 3 namespaces?

[list=1]

[*]yii

[*]app

[*]ext (this one would need sub-namespaces to avoid name collisions)

[/list]

Then we could just do:


<?php


namespace app;


use yii;

Nice and simple! :) Thoughts?

You are not a developer =).

You can alias long namespaces by doing the following:


use yii\helpers\base as Base;

When I develop in C++, I always take care to use the full namespace in the interface, especially when I program libraries to be used by others.

Haven’t used it yet in PHP, but I think it’s a good idea.

In the private implementation, I usually use ‘using namespace long_namespace’ for convenience.

Definitely true. :) I am also not very experienced in using namespaces. I am just curious what the thought process behind sub-namespaces is.

The idea behind sub-namespaces is to group related classes (and thus separating them from unrelated functionalities).