Robert Klemme wrote:
> 2010/8/31 Philipp Kempgen <lists / kempgen.net>:
>> Robert Klemme wrote:
>>> 2010/8/31 Philipp Kempgen <lists / kempgen.net>:

>>>> Actually one of the few nice things about namespaces in PHP is the
>>>> ability to import namespaces/classes using an alias.
>>>>
>>>> use \foovendor\system\Shell as Sh;
>>>> Sh::exec( 'ls' );
>>>
>>> Well, you can do the same in Ruby.  Either use a constant or a local variable:
>>>
>>> Sh = ::FooVendor::System::Shell
>>> Sh.exec 'ls'
>>>
>>> sh = ::FooVendor::System::Shell
>>> sh.exec 'ls'
>>
>> Sure.
>> I guess I'll do some benchmarks. :-)
> 
> I don't expect much differences.  Please share the outcome of the benchmark.

In my totally unscientific benchmarks I did not find any noticeable
divergence. It is certainly well below 1 %. Fine.

ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

However it occurred to me that there is a difference between
namespace aliases in PHP and the closest thing in Ruby (as
described above): Autoloading.

In Ruby the assignment to a constant or variable will not work
if the module/class has not been loaded (obviously) whereas in
PHP I can assign an alias and never use the class.

---PHP-----------------------------------------------------------
use \foovendor\system\Shell as Sh;
if (false) Sh::exec('ls');
if (false) Sh::exec('ls');
-----------------------------------------------------------------

vs.

---Ruby----------------------------------------------------------
Sh = FooVendor::System::Shell
if false; Sh::exec(''); end
if false; Sh::exec(''); end
-----------------------------------------------------------------
(unnecessary autoload)

vs.

---Ruby----------------------------------------------------------
if false; Sh = FooVendor::System::Shell; Sh::exec(''); end
if false; Sh = FooVendor::System::Shell; Sh::exec(''); end
-----------------------------------------------------------------
(ugly)

Whatever. Maybe namespace aliasing could be a nice addition to
Ruby but for the time being the unnecessary autoload wins.


  Philipp