On Wed, Sep 1, 2010 at 11:39 AM, Philipp Kempgen <lists / kempgen.net> wrote: > 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. ¨Βιτθευσγοξσταξτ ος μογαμαςιαβμε>>>> >>>> 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. ¨Βμεασσθαςτθουτγονοζ τθβεξγθναςλ® > > 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] Thanks for sharing your findings! To make it "scientific" you could also post the benchmark code. :-) Then everybody can judge for themselves. Just in case you were not aware there is a nice module Benchmark which allows for easy benchmarking. http://www.ruby-doc.org/stdlib/libdoc/benchmark/rdoc/classes/Benchmark.html http://www.ruby-doc.org/stdlib/libdoc/benchmark/rdoc/index.html > 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. Well, if you alias a namespace that you never use then you have created dead code already. Personally I find it preferable to not encourage people to simply copy and paste code (even if it is a number of namespace aliases) so I'd say it's good the way it is. :-) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/